What will be output of the following program?
Correct Answer : C
Inside main, an integer variable
n is declared and initialized to
5. The next statement is a
do-while loop. The
do loop body is first executed and then the condition is checked. So display statement prints value of
n is then decremented. Then condition
n < 2 is checked which returns
false since the
n with value
4 is not less than
2. So loop terminates and total output is n = 5.
Topic: do while Loop In Java