Read this chapter, which discusses arithmetic operations in greater detail along with solving expressions with mixed data types.
10. Subexpressions
Answer:
0
There is no integer negative zero. So -3/4
evaluates to zero.
Subexpressions
Most of the operators we are interested in take two operands. In each of the following examples the operator has two operands:
34 + 12
|
19/3
|
90 - sum
|
val * x
|
However, unary operators take just one operand:
+93
|
-72
|
+sum
|
-Math.PI
|
A binary operator will always have exactly two operands. However, sometimes one or both operands of a binary operator is a subexpression.
Sometimes a subexpression is a constant, like "8". Any expression can be a subexpression of a larger expression. In the following, both operands of the red operator are subexpressions.
2*3 + 8
|
(x - y) / 2.3
|
(sum - 2) * (sum + 3)
|
When an expression is evaluated, the subexpressions must be evaluated first before the operator that joins them can be applied.
Gotcha: a subexpression may call for integer arithmetic, even though the larger expression calls for floating point. (I keep stressing this, but that is because people get caught by this all the time.)
Question 10:
In an expression like 34.12 / 68.0
how do you know if the /
means
integer division or means floating point division ?