Arithmetic Operators

5 min read ·

Arithmetic operators are used to perform mathematical calculations on numeric data types like int, float, double, long, short and byte.
These operators are mostly used in calculations, loops, billing systems, banking applications and scoring systems.

Arithmetic Operators Table

OperatorNameDescriptionExampleResult
+AdditionAdds two values10 + 515
-SubtractionSubtracts second value from first10 - 55
*MultiplicationMultiplies two values10 * 550
/DivisionDivides first value by second10 / 52
%ModulusReturns remainder10 % 31

1. Addition Operator +

Used to add two numbers.

Example

Output Sum: 50

Addition with Different Data Types

Java automatically converts int to double.

2. Subtraction Operator -

Used to subtract one number from another.

Example

Output Remaining Marks: 28

3. Multiplication Operator *

Used to multiply two numbers.

Example

Output Area: 20

4. Division Operator /

Used to divide one number by another.

Important Concept Integer Division

If both values are integers, Java removes decimal part.

Example 1 Integer Division

Output Result: 3

Example 2 Decimal Division

Output Result: 3.3333333333333335

Example 3 Using Casting


Caution

Division by zero causes ArithmeticException when using integers.

Example Division by Zero

This program will crash at runtime.

5. Modulus Operator %

Returns the remainder after division.

Example

Output Remainder: 1

Real World Usage

Checking Even or Odd

Arithmetic Operators with Mixed Data Types

When different numeric types are used together, Java automatically promotes smaller type to larger type.
Example byte and int result becomes int int and double result becomes double

Operator Precedence in Arithmetic

Operator precedence defines which operation is executed first.
Order of execution
1 Multiplication 2 Division 3 Modulus 4 Addition 5 Subtraction
Example
Output 20
Because multiplication runs first.
Using parentheses changes priority.
Output 30

Practice Exercise

1 Create a program to calculate simple interest using formula SimpleInterest = (P * R * T) / 100
2 Write a program to calculate area of circle
3 Take two numbers and print quotient and remainder separately
Practice these properly because arithmetic operators are base of all programming logic.
Learn Java Arithmetic Operators | Java Course