| 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
Array Traversal and Modification
< Prev
Next >

Assume that the integer array nums has been declared and initialized. Which of the following code segments correctly updates the array by replacing each element with the square of its original value?

I.
int k = 0;
while (k < nums.length)
{
    nums[k] = nums[k] * nums[k];
}

II.
for (int k = 0; k < nums.length; k++)
{
    nums[k] = nums[k] * nums[k];
}

III.
for (int n : nums)
{
    n = n * n;
}
A

II only

B

I and II only

C

I and III only

D

I, II, and III

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