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
πŸ’¬ Discuss
βœ… 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.
Explanation by: Deepak Sahoo
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
269
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Deepak Sahoo
Publisher
πŸ“ˆ
87%
Success Rate