Java Arithmetic Operators

The way we calculate mathematical calculations, in the same way, Java provides arithmetic operators for mathematical operations. It provides operators for all necessary mathematical calculations.

Basic Arithmetic Operators

There are various arithmetic operators used in Java:

+AdditionTo add two operands.
-SubtractionTo subtract two operands.
*MultiplicationTo multiply two operands.
/DivisionTo divide two operands.
%ModulusTo get the area of the division of two operands.

Arithmetic operators are applied on integer and floating-point and not on boolean types. But you can use them on the characters' because, in Java, Char is sub-set of the integer.

Program to Show Arithmetic Operators Works

public class arithop {
 public static void main(String[] args) {
  //Variables Definition and Initialization
  int number1 = 12, number2 = 4;

  //Addition Operation
  int sum = number1 + number2;
  System.out.println("Sum is: " + sum);

  //Subtraction Operation
  int dif = number1 - number2;
  System.out.println("Difference is : " + dif);

  //Multiplication Operation
  int mul = number1 * number2;
  System.out.println("Multiplied value is : " + mul);

  //Division Operation
  int div = number1 / number2;
  System.out.println("Quotient is : " + div);

  //Modulus Operation
  int rem = number1 % number2;
  System.out.println("Remainder is : " + rem);

Sum is: 16
Difference is : 8
Multiplied value is : 48
Quotient is : 3
Remainder is : 0

Scroll Back to Top