A.7 Arithmetic
Most programs perform arithmetic calculations. The arithmetic operators are summarized in Fig. A.11. Note the use of various special symbols not used in algebra. The asterisk (*) indicates multiplication, and the percent sign (%
) is the remainder operator, which we’ll discuss shortly. The arithmetic operators in Fig. A.11 are binary operators, because each operates on two operands. For example, the expression f + 7
contains the binary operator +
and the two operands f
and 7
.
Fig. A.11 Arithmetic operators
Java operation | Operator | Algebraic expression | Java expression |
---|---|---|---|
Addition | + | f + 7 |
f + 7 |
Subtraction | − | p − c |
p − c |
Multiplication | * | bm |
b * m |
Division | / | x/y or or x ÷ y |
x / y |
Remainder | % | r mod s |
r % S |
Integer ...
Get Android How to Program, 3/e 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.