Question 26Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

What will be the output of the following Java code? public class DoWhileExample {

What will be the output of the following Java code? public class DoWhileExample { public static void main(String[] args) { int x = 10; do { System.out.println("x = " + x); x++; } while (x < 13); } }
  1. Ax = 10 x = 11 x = 12
  2. Bx = 10
  3. Cx = 10 x = 11
  4. DNo output
Show answerHide answer

Correct answer: (A) x = 10 x = 11 x = 12

Explanation

A do-while body runs before the test: it prints x = 10, 11 and 12, and stops when x becomes 13 because 13 < 13 is false.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

This is question 26 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.