ArrayIndexOutOfBoundsException:40错误?是什么造成的?

时间:2015-11-13 01:58:42

标签: java arrays

    int[] responses = { 1,2,6,4,8,5,9,7,8,10,1,6,3,8,6,10,3,8,2,7,6,5,7,6,8,6,7,5,6,6,5,6,7,5,6,4,8,6,8,10 };
    int lenResponses = responses.length;
    int sumResponses = 0;
    for(int x=0;x<=lenResponses;x++ )
    {
        sumResponses += responses[x];
    }

上面的代码如何触发异常?我试图找到数组中所有数字的总和。

0 个答案:

没有答案