A

Admin • 828.03K Points
Coach

Q. What is the output of the following code?

Code:
int x = 5;
while (x > 0) {
System.out.println(x);
x--;
}
  • (A) 5 4 3 2 1
  • (B) 1 2 3 4 5
  • (C) 5 4 3 2
  • (D) 1 2 3 4
  • Correct Answer - Option(A)
  • Views: 11
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
The while loop decrements the value of x by 1 on each iteration, and prints its value until x becomes less than or equal to 0.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.