Array Traversal and Modification
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
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE