Numeric Operators

In the last section, we created and initialized some variables. Now let's look at Java's facilities for numeric operations. They will look very familiar to C programmers, but there are some differences. Operators that perform arithmetic or numeric comparison are shown in Table 3.2. The precedence gives the order in which the compiler performs operations, with 1 being the first. You can always use parentheses to control the order in which operations are performed.

Table 3.2. Numeric Operators in Java
PrecedenceOperatorDescription
1++Increment by 1 (or 1.0)
1--Decrement by 1 (or 1.0)
1+Unary plus
1-Unary minus
2*Multiplication
2/Division
2%Modulo
3+Addition
3-Subtraction
5<Less than test
5>Greater than test
5<=Less than/equal test
5>=Greater ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.