GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Arithmetic Operators in Java Programming | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Java Programming Tutorial
  • Java Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Integer Variable
    • Long Variable
    • Short Variable
    • Byte Variable
    • Float and Double Variables
    • Character Variable
    • Boolean Variable
    • Constant Variable
    • Typecasting
  • Operators in Java
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Operator Precedence
  • Input and Output in Java
    • Environment Setup
    • Program Basic Structure
    • Output
    • Input
    • Comments
  • Decision Making in Java
    • Decision Making
    • if Statement
    • if else Statement
    • if else if Statement
    • Conditional Operator
    • switch case Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Java
    • Loops
    • for Loop
    • while Loop
    • do while Loop
  • Arrays in Java
    • One Dimensional Array
    • Two Dimensional Array
  • String in Java
    • String
    • StringBuffer
    • StringBuilder
  • Searching in Java
    • Linear Search
    • Binary Search
  • Sorting in Java
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Java
    • Function
    • Recursive Function
    • Function Overloading
  • OOPs in Java
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Access Modifiers
    • Constructor
    • Static Variables
    • Static Methods
    • Inheritance
    • Interface
    • Types of Inheritance
    • Polymorphism
    • Final Class and Method
    • Abstract Class and Method
    • Wrapper Classes
  • Data Structures in Java
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Packages in Java
    • Packages
  • Exception Handling in Java
    • Exception Handling
    • User-Defined Exception
  • Thread in Java
    • Thread
    • Thread Methods
  • File Handling in Java
    • Text File Handling
    • Binary File Handling
    • Random Access File Handling

bookmark
Table of Contents

    Arithmetic Operators in Java Programming

    In this lesson, we are going to look at what is arithmetic operators and will learn the different types of arithmetic operator with the help of examples.

    What is Arithmetic Operators

    Arithmetic Operators in Java are used to performing arithmetic or mathematical operations on operands.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    Arithmetic Operators are of two types:

    • Unary Operators - Operators that operates or works with a single operand are called unary operators. For example: (++ , --).
    • Binary Operators - Operators that operates or works with two operands are called binary operators. For example: (+, –, *, /, %).

    Unary Operators

    There are 2 types of Unary operators:

    • Increment Operator ++
    • Decrement Operator --

    Increment Operator ++

    The Increment Operator increases the value of a variable by 1.

    There are 2 types of Increment Operators and they are:

    • Pre-Increment
    • Post-Increment

    Pre-Increment

    The Pre-Increment operator increases the value of a variable by 1 before using it in an expression. In Pre-Increment, the value is first increased by 1 and then used inside the expression.

    Example
    int x=5, y;
    y = ++x;  // value of x is increase by 1 and then stored in y, so y = x + 1 (y = 5 + 1) y=6

    In the example above, the value of x which is 5 is first increase by 1 and then stored in x. So the result of y is 6.

    Post-Increment

    The Post-Increment operator increases the value of a variable by 1 after the expression in which the post-increment is used is fully evaluated. In Post-Increment, the current value is used in the expression first, and then the variable is increased by 1. Let's see an example for better understanding.

    Example
    int x=5, y;
    y = x++;  // value of x is stored in y first and after that x is increase by 1, so y=x (y=5) and x = x + 1 (x = 5 + 1) x=6

    In the example above, the value of x which is 5 is first stored in y and after that increased by 1. So the result of y is 5 and the value of x becomes 6.

    Decrement Operator --

    Decrement Operator decreases the value of a variable by 1.

    There are 2 types of Decrement Operators and they are:

    • Pre-Decrement
    • Post-Decrement

    Pre-Decrement

    The Pre-Decrement operator decreases the value of a variable by 1 before using it in an expression. In Pre-Decrement, the value is first decreased by 1 and then used inside the expression.

    Example
    int x=5, y;
    y = --x;  // value of x is decrease by 1 and then stored in y, so y = (x - 1) (y = 5 - 1) y=4 and x=4

    In the example above, the value of x which is 5 is first decrease by 1 and then stored in x. So the result of y is 4 and x is also 4.

    Post-Decrement

    The Post-Decrement operator decreases the value of a variable by 1 after the expression in which the post-decrement is used is fully evaluated. In Post-Decrement, the current value is used in the expression first, and then the variable is decreased by 1. Let's see an example for better understanding.

    Example
    int x=5, y;
    y = x--;  // value of x is stored in y first and after that x is decrease by 1, so y=x (y=5) and x = x - 1 (x=5-1) x=4

    In the example above, the value of x which is 5 is first stored in y and after that decreased by 1. So the result of y is 5 and the value of x becomes 4.

    Binary Operators

    There are 5 types of binary operators:

    • + Addition
    • - Subtraction
    • * Multiplication
    • / Division
    • % Modulus

    Addition Operator +

    The Addition Operator + is used for adding the value of two or more variables.

    Example
    int x=5, y=2, z;
    z = x + y;  // value of z = 5 + 2 result z=7

    In the example above, the value of x and y is first added and then stored in z. So the result of z is 7.

    Subtraction Operator -

    The Subtraction Operator - is used for subtracting the value of two or more variables.

    Example
    int x=5, y=2, z;
    z = x - y;  // value of z = 5 - 2 result z=3

    In the example above, the value of y is subtracted from x and the final result is stored in z. So the result of z is 3.

    Multiplication Operator *

    The Multiplication Operator * is used for multiplying the value of two or more variables.

    Example
    int x=5, y=2, z;
    z = x * y;  // value of z = 5 * 2 result z=10

    In the example above, the value of x and y is first multiplied and then stored in z. So the result of z is 10.

    Division Operator /

    The Division Operator / is used for dividing the value of two or more variables and the quotient is returned as the result of the division. Let's see the example for more understanding.

    Example
    int x=5, y=2, z;
    z = x / y;  // value of z = 5 / 2 result z=2 which is a quotient

    In the example above, the value of x and y is first divided and then stored the quotient in z. So the result of z is 2. Here x and y both are integer variable so the result of their division will be in integer only.

    Modulus Operator %

    The Modulus Operator % is used for dividing the value of two or more variables and the remainder is returned as the result of the division. Let's see the example for more understanding.

    Example
    int x=5, y=2, z;
    z = x % y;  // value of z = 5 % 2 result z=1 which is a remainder

    In the example above, the value of x and y is first divided and then stored the remainder in z. So the result of z is 1.

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.