Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误->;java.lang.ArrayIndexOutofBounds异常:8_Java_Arrays_Indexoutofboundsexception - Fatal编程技术网

错误->;java.lang.ArrayIndexOutofBounds异常:8

错误->;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;

我创建了这个选择题程序,一切都很好,正确答案正在打印出来,但我一直得到:

线程“main”java.lang.ArrayIndexOutOfBoundsException中的异常:8在multipleChices.main(multipleChices.java:21)

有人能告诉我需要做什么来修复这个错误吗

        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那么如何修复此错误?