August 2004
Intermediate to advanced
480 pages
9h 41m
English
The compiler will follow certain rules when determining how to execute a mathematical statement containing multiple operators.
Lucky for us, they are the standard rules regarding operator precedence:
Operators inside parentheses are evaluated first.
Multiplication and division (left to right).
Addition and subtraction (left to right).
The following code illustrates these concepts.
public class OpPrecedence {
public static void main(String[] args) {
short x = 10 + 9 / 3 * 2 - 5 + (4 - 2);
System.out.println(x);
}
}
That code is a complete class that you can type in, compile, and run. I know we haven't talked about classes yet, but I'm going to try to do that a lot so you can get comfortable typing the code ...
Read now
Unlock full access