Here we go... when I try an example with 3 students and 3 classes, the input works fine until the last class, where it throws an exception. This doesn't make sense because the length should fit the for loop... Can anyone find what's wrong here?
import java.io.*;
public class Application
{
public static void main()
{
int studentNum = 0;
int courseNum = 0;
System.out.println("\f------GRADE CALCULATOR------\n");
try
{
BufferedReader buffin = new BufferedReader(new InputStreamReader (System.in));
System.out.print("Enter number of students: ");
System.out.flush();
studentNum = Integer.parseInt(buffin.readLine());
System.out.print("Enter number of courses to compute grades for: ");
System.out.flush();
courseNum = Integer.parseInt(buffin.readLine());
int grades[][] = {new int[studentNum], new int[courseNum]};
System.out.println("\nEntering grades for " + studentNum + " students for " + courseNum + " classes.\n");
System.out.println(grades.length);
for (int i = 0; i < studentNum; i++)
{
System.out.println("Entering grades for student #" + (i+1) + "...");
for (int k = 0; k < courseNum; k++)
{
System.out.print("Enter grade recieved in course #" + (k+1) + ": ");
System.out.flush();
char letterGrade = (buffin.readLine()).charAt(0);
if (letterGrade == 'A' || letterGrade == 'a')
grades[i][k] = 4;
else if (letterGrade == 'B' || letterGrade == 'b')
grades[i][k] = 3;
else if (letterGrade == 'C' || letterGrade == 'c')
grades[i][k] = 2;
else if (letterGrade == 'D' || letterGrade == 'd')
grades[i][k] = 1;
else if (letterGrade == 'F' || letterGrade == 'f')
grades[i][k] = 0;
else
{
System.out.println("\nInvalid entry! Acceptable inputs are A, B, C, D, or F.\n");
k--;
}
}
}
}
catch (IOException e)
{
}
}
}