What is the output of the following 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
Solution: 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.