这段代码中抛出的异常是什么:

Ste*_*nte 0 java exception

public class Testex
{
    public static void main ( String[] args ) {
       double [] scores = new double [5];
       scores [5] = 95.75;

    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道这里抛出了什么异常,请帮忙

小智 7

double [5]不是数组中的最后一个元素,double [4]是(数组在java中从零开始)


Jus*_*ner 5

这将是一个Index Out Of Range Exception(数组基于0,而不是基于1):

 scores[5] = 95.75; // references the sixth element of a five element array
Run Code Online (Sandbox Code Playgroud)