What is the Java corresponding to this tree?
A: z = y + 3 * x
B: z = x * y + 3
C: z = (3 + y) * x
D: z = (y + 3) * x
E: z = x * (y + 3)
There are several things to remember in order to get this right:
- An operator goes together with its children.
Thus, + must connect y and 3.
- Order: the expression must have the same left-to-right order as
the tree: y + 3, not 3 + y.
- Precedence: since + has lower precedence than *,
a + expression in the scope of a * operator must be