Answer to Question #149668 in Java | JSP | JSF for Jazzz

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);
1
Expert's answer
2020-12-08T15:11:23-0500

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog