Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
medium Solved by 2 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[0], arr[1], …, arr[arr.length] will be stored in sum.

B

An infinite loop will occur.

C

A run-time error will occur.

D

Sum of arr[1], arr[2], …, arr[arr.length-1] will be stored in sum.

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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