Currently working on a project that requests the number of classes a student has left, the amount of classes taken per term, and returns the number of terms left to graduate. I'm having some trouble figuring out how to cast an integer array to a double array to figure out the amount of terms needed. Also the result needs to round up as well. I'm very new to this so any suggestions are much appreciated and critiques on how to clean up my code, thanks in advance.
import java.util.Scanner;
public class main {
public static void main (String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter the number of rows: ");
int rows = input.nextInt();
System.out.print("Enter the number of columns: ");
int columns = input.nextInt();
int [][] studentArray = new int [rows][columns];
for (int i = 0; i <= rows-1; i++) {
for (int j = 0; j <= columns-1; j++) {
if (j==0) {
System.out.print("Please enter the number of classes left for student " +(i+1)+ " : ");
studentArray[i][j] = input.nextInt();
}
else if (j>0) {
System.out.print("Enter the number of classes taken per term : ");
studentArray[i][j] = input.nextInt();
while (studentArray[i][j] >= 6) {
System.out.println("The number of classes per term for student " +(i+1)+ " is not valid!");
System.out.print("Enter the number of classes taken per term : ");
studentArray[i][j] = input.nextInt();
}
}
}
}
divide(studentArray);
}
public static void divide(int termsLeft[][]) {
for (int k = 0; k < termsLeft.length; k++) {
double result = termsLeft[k][0] / termsLeft[k][1];
if (k>=0) {
System.out.println("Student " +(k+1)+ " has " + result + " terms left to graduate.");
}
}
}
}
int[]is anint[], and not adouble[].