1Z0-808 · Question #37
if (@Var++ < 10) { System.out.println (@Var + " Hello World!"); } else { System.out.println (@Var + " Hello Universe!"); } What is the result if the integer aVar is 9?
The correct answer is A. Hello World! Option A is correct because aVar++ is post-increment: it uses the current value (9) in the comparison before incrementing, so the condition evaluates as 9 < 10 → true, entering the if-block and printing 10 Hello World!. Option B is wrong because the else-block is never reached…
Question
Options
- AHello World!
- BHello Universe!
- CHello World
- DCompilation fails.
How the community answered
(25 responses)- A92% (23)
- B4% (1)
- D4% (1)
Explanation
Option A is correct because aVar++ is post-increment: it uses the current value (9) in the comparison before incrementing, so the condition evaluates as 9 < 10 → true, entering the if-block and printing 10 Hello World!. Option B is wrong because the else-block is never reached - the condition was satisfied. Option C is wrong because the output literally contains an exclamation mark (!), so Hello World without it doesn't match. Option D is wrong because the code is syntactically valid and compiles without errors.
Memory tip: Think of x++ as "use it, then boost it" - the old value does the comparison work, and only after that does the variable step up by 1.
Topics
Community Discussion
No community discussion yet for this question.