Ich versuche ein einfaches Programm zu erstellen, das die Gesamtnote von 3 Studenten berechnet, indem ich die einzelnen Markierungen durch einen Konstruktor übergebe.Warum bekomme ich ArrayIndexOutOfBounds Ausnahme?
class Student{
int n;
int[] total = new int[n];
Student(int x, int[] p, int[] c, int[] m){
int n = x;
for(int i = 0; i < n; i++){
total[i] = (p[i] + c[i] + m[i]);
System.out.println(total[i]);
}
}
}
class Mlist{
public static void main(String args[]){
String[] name = {"foo", "bar", "baz"};
int[] phy = {80,112,100};
int[] chem = {100,120,88};
int[] maths = {40, 68,60};
Student stud = new Student(name.length, phy, chem, maths);
}
}