No announcement
 

Arithmetic Operators

The usual arithmetic operators are:-

  1. Addition, +
    It adds value on either side of the operator.
  2. Subtraction, -
    It subtracts right-hand value from the left-hand value.
  3. Multiplication, *
    It multiplies value on either side of the operator.
  4. Division, /
    It divides left-hand value by the right-hand value.
  5. Modulus, %
    It returns the remainder after division operation.

Example:

ArithmeticOperatorsDemo.java

package com.codingnous.tutorial;

public class ArithmeticOperatorsDemo {

	public static void main(String[] args) {
		// Two values for performing the arithmetic operations
		int num1 = 100;
		int num2 = 22;

		// Addition operation
		int additionResult = num1 + num2;

		// Subtraction operation
		int subtractionResult = num1 - num2;

		// Multiplication operation
		int multiplicationResult = num1 * num2;

		// Division operation (typecast to retain decimal fraction)
		float divisionResult = (float) num1 / num2;

		// Modulus operation
		int modulusResult = num1 % num2;

		// Printing the results
		System.out.println("Arithmetic operation results:-");
		System.out.println(num1 + " + " + num2 + " = " + additionResult);
		System.out.println(num1 + " - " + num2 + " = " + subtractionResult);
		System.out.println(num1 + " * " + num2 + " = " + multiplicationResult);
		System.out.println(num1 + " / " + num2 + " = " + divisionResult);
		System.out.println(num1 + " % " + num2 + " = " + modulusResult);
	}

}

Output
Arithmetic operation results:- 100 + 22 = 122 100 - 22 = 78 100 * 22 = 2200 100 / 22 = 4.5454545 100 % 22 = 12