错误->;java.lang.ArrayIndexOutofBounds异常:8
我创建了这个选择题程序,一切都很好,正确答案正在打印出来,但我一直得到: 线程“main”java.lang.ArrayIndexOutOfBoundsException中的异常:8在multipleChices.main(multipleChices.java:21) 有人能告诉我需要做什么来修复这个错误吗错误->;java.lang.ArrayIndexOutofBounds异常:8,java,arrays,indexoutofboundsexception,Java,Arrays,Indexoutofboundsexception,我创建了这个选择题程序,一切都很好,正确答案正在打印出来,但我一直得到: 线程“main”java.lang.ArrayIndexOutOfBoundsException中的异常:8在multipleChices.main(multipleChices.java:21) 有人能告诉我需要做什么来修复这个错误吗 for(int i = 0; i < student[i].length; i++){ int rightAns = 0;
for(int i = 0; i < student[i].length; i++){
int rightAns = 0;
for(int j = 0; j < student[i].length; j++){
if(student[i][j].equalsIgnoreCase(key[j])){
rightAns++;
}
}
for(int i=0;i
您的第一个for循环使用了错误的值。您应该使用student.length而不是student[i]
for(int i = 0; i < student.length; i++){
int rightAns = 0;
for(int j = 0; j < student[i].length; j++){
if(student[i][j].equalsIgnoreCase(key[j])){
rightAns++;
}
}
System.out.print("Student's " + i + "#correct answer: " + rightAns + "\n");
}
}
for(int i=0;i
问题是您试图获取仅包含8个元素的数组的第9个元素。@Stultuske那么如何修复此错误?