1Z0-808 · Question #65
What is the result? int i, j=0; i = (3 2 +4 +5) ; j = (3 ((2+4) + 5)); System.out.println("i:" + i + "\nj:" +j);
The correct answer is B. i: 15 j: 33. Option B is correct because Java's operator precedence causes ` to execute before + in the first expression: 3 2 + 4 + 5 = 6 + 4 + 5 = 15, and in the second expression, the inner parentheses force (2+4) = 6 first, then (6+5) = 11, then 3 11 = 33. A (i:16) is wrong due to an…
Question
Options
- Ai: 16 j: 33
- Bi: 15 j: 33
- Ci: 33 j: 23
- Di: 15 j: 23
How the community answered
(22 responses)- B91% (20)
- C5% (1)
- D5% (1)
Explanation
Option B is correct because Java's operator precedence causes * to execute before + in the first expression: 3 * 2 + 4 + 5 = 6 + 4 + 5 = 15, and in the second expression, the inner parentheses force (2+4) = 6 first, then (6+5) = 11, then 3 * 11 = 33.
A (i:16) is wrong due to an arithmetic error - there is no combination of legal evaluation order that yields 16 for that expression. C (i:33, j:23) swaps the two values and gets both wrong. D (i:15, j:23) gets i right but miscalculates j by ignoring the outer grouping - this is the sneaky distractor, likely from computing (3*(2+4))+5 = 18+5 = 23 instead of 3*((2+4)+5) = 3*11 = 33.
Memory tip: "Parentheses are promises" - whatever is inside must be fully resolved before anything outside touches it, so work strictly inside-out, then apply standard PEMDAS/BODMAS for the rest.
Topics
Community Discussion
No community discussion yet for this question.