0 votes
in JAVA by

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

1 Answer

0 votes
by

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.

Related questions

0 votes
asked May 4, 2021 in JAVA by SakshiSharma
0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
...