🎴 Flashcard Mode
Java Programming Fundamentals
Card1 / 20
Mastered0
Review0
QuestionClick to flip
What is the output of the following program? public class example { public static void main(String args[]) { int x=0, y=2; do { x=++x; y--; } while(y>0); System.out.println(x); } }
AnswerClick to flip back
A
2
💡 Explanation:
The loop runs twice. In the first iteration, x becomes 1 (via ++x) and y becomes 1. In the second iteration, x becomes 2 and y becomes 0. The loop terminates, and 2 is printed.