Q. What is the output of the following code?
Code:
int x = 5;
while (x > 0) {
System.out.println(x);
x--;
}
β
Correct Answer: (A)
5 4 3 2 1
Explanation: 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.