402,063 views
5 votes
5 votes
Please help me with this coding assignment :)

What values are stored in nums after the following code segment has been executed?

int[] nums = {50, 100, 150, 200, 250};
for (int n : nums)
{
n = n / nums[0];
}
[1, 2, 3, 4, 5]
[1, 1, 1, 1, 1]
[1, 100, 150, 200, 250]
[50, 100, 150, 200, 250]

User Alhcr
by
2.9k points

1 Answer

20 votes
20 votes

Answer:

D. [50, 100, 150, 200, 250]

Step-by-step explanation:

This is a trick question because the integer n is only a counter and does not affect the array nums. To change the actual array it would have to say...nums[n] = n/nums[0];

User Matias Elorriaga
by
2.5k points