Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Q.A Academy
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java
  • Java Arithmetic Operators

Java Arithmetic Operators

What is Java Operator?

In Java programming, an operator is a special symbol that performs operations on variables and values. Operators are used to manipulate data and variables in expressions. Java operators can be categorized into several types:

Arithmetic Operators

In Java, arithmetic operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and modulus. These operators work with primitive data types like int, float, double, long, and others.

List of Arithmetic Operators #

  1. Addition (+)
  2. Subtraction (–)
  3. Multiplication (*)
  4. Division (/)
  5. Modulus (%)
  6. Increment (++)
  7. Decrement (—)

Examples and Explanations #

1. Addition (+)

The addition operator adds two operands.

public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        int sum = a + b;

        System.out.println("Sum: " + sum);  

    }

}

Output: 
Sum: 30

2. Subtraction (–)

The subtraction operator subtracts the right operand from the left operand.

public class Main {

    public static void main(String[] args) {

        int a = 20;

        int b = 10;

        int difference = a - b;

        System.out.println("Difference: " + difference);  

    }

}

Output: 
Difference: 10

3. Multiplication (*)

The multiplication operator multiplies two operands.

public class Main {

    public static void main(String[] args) {

        int a = 10;

        int b = 20;

        int product = a * b;

        System.out.println("Product: " + product);  

    }

}

Output:
Product: 200

4. Division (/)

The division operator divides the left operand by the right operand. For integer division, it returns the quotient and discards the remainder.

public class Main {

    public static void main(String[] args) {

        int a = 20;

        int b = 10;

        int quotient = a / b;

        System.out.println("Quotient: " + quotient);  

        double x = 20.0;

        double y = 3.0;

        double result = x / y;

        System.out.println("Result: " + result);  

    }

}

Output:
Quotient: 2
Result: 6.666666666666667

5. Modulus (%)

The modulus operator returns the remainder of the division of the left operand by the right operand.

public class Main {

    public static void main(String[] args) {

        int a = 20;

        int b = 3;

        int remainder = a % b;

        System.out.println("Remainder: " + remainder);  

    }

}

Output: 
Remainder: 2

6. Increment (++)

The increment operator increases the value of a variable by 1. It can be used as a prefix or postfix.

  • Prefix (++variable): Increments the value before using it in an expression.
  • Postfix (variable++): Increments the value after using it in an expression.

public class Main {

    public static void main(String[] args) {

        int a = 10;

        System.out.println("Prefix Increment: " + (++a));  

        a = 10;

        System.out.println("Postfix Increment: " + (a++));  

        System.out.println("After Postfix Increment: " + a); 

    }

}

Output: 
Prefix Increment: 11
Postfix Increment: 10
After Postfix Increment: 11

7. Decrement (—)

The decrement operator decreases the value of a variable by 1. It can be used as a prefix or postfix.

  • Prefix (–variable): Decrements the value before using it in an expression.
  • Postfix (variable–): Decrements the value after using it in an expression.

public class Main {

    public static void main(String[] args) {

        int a = 10;

        System.out.println("Prefix Decrement: " + (--a));  

        a = 10;

        System.out.println("Postfix Decrement: " + (a--));  

        System.out.println("After Postfix Decrement: " + a);  

    }

}

Output: 
Prefix Decrement: 9
Postfix Decrement: 10
After Postfix Decrement: 9

Summary #

Arithmetic operators are fundamental in performing mathematical calculations in Java programs. Understanding how to use each operator and the difference between prefix and postfix increment/decrement is essential for writing effective and accurate code.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
Type CastingRelational Operators
Table of Contents
  • List of Arithmetic Operators
  • Examples and Explanations
  • Summary
© Copyright [2018-2025]. All Rights Reserved.