Java Arithmetic Operators

The arithmetic operators are used in mathematical operations as like as they are used in algebra. They are commonly used for addition, subtraction, multiplication, division etc.

A list of relational operators used in Java language:

Assume two variables "a" and "b", having the value 50 and 100 respectively.

S.No. Operators Example Description
1. + (addition) a + b will give 150. It is used to add values on the both side of the operator.
2. - (subtraction) a - b will give -50. It is used to subtract right-hand operand from left-hand operand.
3. * (multiplication) a * b will give 5000. It is used to multiply values on both side of the operator.
4. / (division) b / a will give 2. It is used to divide left-hand operand by right-hand operand.
5. % (modulus) b % a will give 0. It is used to divide left-hand operand by right-hand operand and returns remainder.
6. ++ (increment) b++ gives 101. It is used to increase the value of operand by 1.
7. -- (Decrement) b-- gives 99 It is used to decrease the value of operand by 1.

Arithmetic Operators Example


/**
 * 
 * @author JavaTportal Corporation  
 *
 */
public class ArithmeticOperatorsExample {

	public static void main(String args[]) {
		int a = 20;
		int b = 30;
		int c = 25;
		int d = 25;

		System.out.println("a + b = " + (a + b));
		System.out.println("a - b = " + (a - b));
		System.out.println("a * b = " + (a * b));
		System.out.println("b / a = " + (b / a));
		System.out.println("b % a = " + (b % a));
		System.out.println("c % a = " + (c % a));
		System.out.println("a++   = " + (a++));
		System.out.println("b--   = " + (a--));
		System.out.println("d++   = " + (d++));
		System.out.println("++d   = " + (++d));
	}
}

Output

a + b = 50
a - b = -10
a * b = 600
b / a = 1
b % a = 10
c % a = 5
a++   = 20
b--   = 21
d++   = 25
++d   = 27

Next Concept Relational Operators