代码从这里开始:
System.out.print("Please enter number of rows: ");
rows = keyboard.nextInt();
while(rows > MAX_ROWS || 0 > rows){
System.out.print("ERROR: Out of range, try again: ");
rows = keyboard.nextInt();
}
rowsTotal = new double[rows];
positions = new double [rows][];
for(index = 0; index < rowsTotal.length; index++){
System.out.print("Please enter number of positions in row " + (char)(index+65) + " : ");
pos = keyboard.nextInt();
if(pos > MAX_POSITIONS){
System.out.print("ERROR: Out of range, try again: ");
pos = keyboard.nextInt();
}
positions[index] = new double[pos];
}
while(input != 'X'){
System.out.print("(A)dd, (R)emove, (P)rint, e(X)it : ");
input = keyboard.next().charAt(0);
input = Character.toUpperCase(input);
if(input == 'P'){
for(int index1= 0; index1 < rowsTotal.length; index1++){
System.out.print((char)(index1+65) + ": " );
for(int pos1= 0; pos1 < pos; pos1++){
**System.out.print(positions[index1][pos] + " ");**
}
System.out.print("[ " + totals + ", " + " " + averages + "]");
System.out.println();
}
}
错误信息如下:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at xxxxx.main(xxxxx.java:75)
这是这行代码System.out.print(positions[index1][pos] + " ");