The built-in data types are supported by a collection of arithmetic, relational, logical, and compound assignment operators. The arithmetic operators are unsurprising except for integer division and the remainder operator:
// Arithmetic Operators + addition a + b - subtraction a - b * multiplication a * b / division a / b % remainder a % b
The division of two integer values yields a whole number. Any remainder is truncated; there is no rounding. The remainder is accessed using the % operator:
5 / 3 evaluates to 1 while 5 % 3 evaluates to 2 5 / 4 evaluates to 1 while 5 % 4 evaluates to 1 5 / 5 evaluates to 1 while 5 % 5 evaluates to 0
When might we actually use the remainder operator? Imagine that we want to ...