While Loop Array Indexing Error
Consider the following code segment. Assume that arr is a non-empty int array.
int sum = arr[0], i = 0;
while (i < arr.length) {
i++;
sum += arr[i];
}
Which of the following best describes the result of executing the code segment?
A
Sum of arr[1], arr[2], …, arr[arr.length-1] will be stored in sum.
B
Sum of arr[0], arr[1], …, arr[arr.length] will be stored in sum.
C
A run-time error will occur.
D
An infinite loop will occur.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE