Home / Programming MCQs / JAVA MCQs / Question

D

Deepak Sahoo • 10.60K Points
Tutor II

Q. What is the output of the following code?

Code:
int x = 0;
do {
System.out.println(x);
x++;
} while (x < 5);
(A) 0 1 2 3 4
(B) 1 2 3 4 5
(C) 0 1 2 3
(D) 1 2 3 4
Explanation by: Deepak Sahoo
The do-while loop prints the value of x on each iteration until x becomes greater than or equal to 5.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.