99.7k views
3 votes
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]
An ArithmeticException is thrown.

User Mouser
by
3.1k points

1 Answer

2 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 JustinMichaels
by
2.9k points