| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
medium Solved by 4 students
While Loop Array Indexing Error
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy