Question 48Asked in DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2

What is the output of the following java code? int m = 1000;

What is the output of the following java code? int m = 1000; int k = 3000; while (++m < --k); System.out.println(m);
  1. AError
  2. B1000
  3. C2000
  4. D4000
Show answerHide answer

Correct answer: (C) 2000

Explanation

Each test increments m and decrements k. The loop stops when m >= k, which first happens at m = 2000, k = 2000 (1000 iterations). So 2000 is printed.

From DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2

This is question 48 of DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2. 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.