Java OCA OCP Practice Question 1734

Question

What is the value of the expression (1 / 2 + 3 / 2 + 0.1)?

Select the one correct answer.

  • (a) 1
  • (b) 1.1
  • (c) 1.6
  • (d) 2
  • (e) 2.1


(b)

Note

The / operator has higher precedence than the + operator.

This means that the expression is evaluated as ((1/2) + (3/2) + 0.1).

The associativity of the binary operators is from left to right, giving (((1/2) + (3/2)) + 0.1).

Integer division results in ((0 + 1) + 0.1) which evaluates to 1.1.




PreviousNext

Related