Question #149668

What is the output of the following Java code?

count = 1;

y = 10;

while (count < 10)

{

y = y - 1;

count++;

}

System.out.println("y = " + y + " and count = " + count);

Expert's answer

Output:

y = 1 and count = 10

As 'count' increments by 1 every iteration, the cycle will finish when it hits 10. As the initial value is 1, the number of iterations is 9. So 'y' will decrement 9 times, and the final value will be 10 - 9 = 1.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS