nerdexam
Oracle

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.

Using Operators and Decision Constructs

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)
  • B
    91% (21)
  • C
    4% (1)
  • D
    4% (1)

Why each option

This question tests the understanding of Java's operator precedence rules for arithmetic operations and assignment.

AOption A

This option would imply incorrect calculations for `i` or `j`, such as misinterpreting the order of operations or basic arithmetic results.

BOption BCorrect

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'.

COption A

This option would imply incorrect calculations for `i` or `j`, indicating a misunderstanding of operator precedence.

DOption D

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

#operator precedence#arithmetic operators#code tracing

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice