0
    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];
    }

How did the code above trigger the exception? I was trying to find the sum of all numbers in the array.

wei chen
  • 1
  • 1
  • thanks so much dude, I was clueless that it ended on 39 because it started counting at 0, big mistake haha – wei chen Nov 13 '15 at 02:01
  • No problem. Remember length is how many elements is in it and indexing starts at 0 so it would be (length-1) – 3kings Nov 13 '15 at 02:03

0 Answers0