I'm writing a simple Java code and I'm getting this error after entering the first input:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at university.GetStudentSpect(university.java:26)
at university.main(university.java:11)
Code:
import java.util.Scanner;
public class university {
public static Scanner Reader = new Scanner(System.in);
public static int n;
public static int m=0;
public static int l;
public static StringBuilder SConverter = new StringBuilder();
public static void main(String[] args) {
GetStudentsNumber();
GetStudentSpect();
}
public static void GetStudentsNumber() {
System.out.println("enter the number of students");
n = Reader.nextInt();
}
public static String [][] StudentSpect = new String [n][2];
public static void GetStudentSpect() {
for (int i=0;i<n;i++) {
System.out.println("enter the name of the student");
StudentSpect[i][0] = SConverter.append(Reader.nextInt()).toString();
System.out.println("enter the id of the student");
StudentSpect[i][1] = SConverter.append(Reader.nextInt()).toString();
System.out.println("enter the number of courses of the student");
l = Reader.nextInt();
m += l;
StudentSpect[i][2] = SConverter.append(l).toString();
}
}
}