19.2k views
2 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 Skylize
by
6.1k points

1 Answer

3 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 Ansel
by
6.6k points