Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Increment/Decrement Operators
- The Arithmetic Operators:
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators:
Assume integer variable A holds 10 and variable B holds 20, then:
SR.NO | Operator and Example |
1 | + ( Addition )
Adds values on either side of the operator Example: A + B will give 30 |
2 | – ( Subtraction )
Subtracts right hand operand from left hand operand Example: A – B will give -10 |
3 | * ( Multiplication )
Multiplies values on either side of the operator Example: A * B will give 200 |
4 | / (Division)
Divides left hand operand by right hand operand Example: B / A will give 2 |
5 | % (Modulus)
Divides left hand operand by right hand operand and returns remainder Example: B % A will give 0 |
6 | ++ (Increment)
Increases the value of operand by 1 Example: B++ gives 21 |
7 | — ( Decrement )
Decreases the value of operand by 1 Example: B– gives 19 |