Skip to main content

Java: Arithmetic Operator

​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
Submitted by arilio666 on October 7, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.