Most programs perform arithmetic calculations. The arithmetic operators are summarized in Fig. 2.11. Note the use of various special symbols not used in algebra. The asterisk (*) indicates multiplication, and the percent sign (%) is the remainder operator (called modulus in some languages), which we will discuss shortly. The arithmetic operators in Fig. 2.11 are binary operators because they each operate on two operands. For example, the expression f + 7 contains the binary operator + and the two operands f and 7.
Java operation | Arithmetic operator | Algebraic expression | Java expression |
---|---|---|---|
Addition | + | f + 7 | f + 7 |
Subtraction | – | p – c | p – c |
Multiplication | * | bm | b * m |
Division | / | x / y oror x ÷ y | x / y |
Remainder | % | r mod ... |
No credit card required