Java: Arithmetic Operator

Profile picture for user arilio666

​An arithmetic operator is a type of operator used to do some simple mathematical stuff in the java programming language.

An arithmetic operator is comprised of many mathematical functions to do the math stuff. Arithmetic Operators are ( +, -, *, /, %), we will see one by one with a perfect code example to understand what is happening in a code while using arithmetic operators.

  1. + (Addition): The + is an operator that performs the additional math function using the operands/value we assign in a variable.
  2. - (Subtraction): The - is an operator which performs the subtraction math function using some of the operands/values we assign in a variable same as the + function.
  3. * (Multiplication): The * is an operator which performs the multiplication math function using the operands we assign.
  4. / (Division): The / operator divides the assigned operand/value.
  5. % (Modulus): The modulus operator % divides the provided value and gives out the remainder/leftover.

Example

package com.javaframework.test;

public class Testing 
{
    public static void main(String[] args) 
    {
        int x = 50, y = 50;
        System.out.println("+ : " +(x + y));
        System.out.println("- : " +(x - y));
        System.out.println("* : " +(x * y));
        System.out.println("/ : " +(x / y));
        System.out.println("% : " +(x % y));
    }
}

Output:

+ : 100
- : 0
* : 2500
/ : 1
% : 0
Tags