+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (also called remainder)
Notice: no exponent! While there is no exponentiation symbol in Java, there is a Math.pow ( ) method which will be discussed later.
The MODULUS Operator %
The modulus operator finds the modulus of its first operand with respect to the second. That is, it produces the remainder of dividing the first value by the second value. For example:
22 % 6 = 4 because 22 / 6 = 3 with a remainder of 4
Confusing DIVISIONS
Be careful when performing integer division. When dividing an integer by an integer, the answer will be an integer (not rounded).
Compare these divisions: (5 is an integer while 5.0 is a double)
Integer division 8 / 5 = 1
Double division 8.0 / 5.0 = 1.6
Mixed division 8.0 / 5 = 1.6
When an operation involves two types (as the mixed division shown above), the smaller type is converted to the larger type. In the case above, the integer 5 was converted to a double type before the division occurred.