1Z0-809 · Question #93
Given: public class App { public static void main (String[] args) { int i = 10; int j = 20; int k = j + i / 5; System.out.print (i + " : " + j + " : " + k); } } What is the result?
The correct answer is B. 10 : 20 : 22. Option B is correct because Java's operator precedence evaluates division before addition, so k = j + i / 5 computes as k = 20 + (10 / 5) = 20 + 2 = 22, and neither i nor j are modified, giving output 10 : 20 : 22. A (10 : 22 : 20) is wrong because it swaps the printed values…
Question
Options
- A10 : 22 : 20
- B10 : 20 : 22
- C10 : 22 : 4
- D10 : 30 : 6
How the community answered
(59 responses)- A5% (3)
- B85% (50)
- C2% (1)
- D8% (5)
Explanation
Option B is correct because Java's operator precedence evaluates division before addition, so k = j + i / 5 computes as k = 20 + (10 / 5) = 20 + 2 = 22, and neither i nor j are modified, giving output 10 : 20 : 22.
A (10 : 22 : 20) is wrong because it swaps the printed values of j and k - j is always 20 and k is always 22, not the reverse.
C (10 : 22 : 4) incorrectly shows j as 22 (it was never changed), and D (10 : 30 : 6) makes the classic mistake of computing (j + i) / 5 = 30 / 5 = 6 - treating the expression left-to-right without respecting that / outranks +.
Memory tip: When you see a mixed + and / expression in Java, mentally add parentheses around the division first - j + (i / 5) - because multiplication and division always win over addition and subtraction, just like standard math.
Community Discussion
No community discussion yet for this question.