1Z0-803 · Question #80
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. Option B. This question tests the understanding of Java's operator precedence rules for arithmetic operations and assignment.
Question
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);
Options
- AOption A
- BOption B
- COption A
- DOption D
How the community answered
(23 responses)- B91% (21)
- C4% (1)
- D4% (1)
Why each option
This question tests the understanding of Java's operator precedence rules for arithmetic operations and assignment.
This option would imply incorrect calculations for `i` or `j`, such as misinterpreting the order of operations or basic arithmetic results.
The variable `i` is calculated as `(3 * 2) + 4 + 5`, which evaluates to `6 + 4 + 5 = 15`. The variable `j` is calculated as `3 * ((2 + 4) + 5)`. The innermost parentheses `(2 + 4)` evaluate to `6`, then `(6 + 5)` evaluates to `11`, and finally `3 * 11` evaluates to `33`. Thus, `i` is 15 and `j` is 33, producing the output 'i:15\nj:33'.
This option would imply incorrect calculations for `i` or `j`, indicating a misunderstanding of operator precedence.
This option would imply incorrect calculations for `i` or `j`, suggesting errors in evaluating the arithmetic expressions.
Concept tested: Java operator precedence and arithmetic evaluation
Topics
Community Discussion
No community discussion yet for this question.