Arithmetic operators in Java

Arithmetic operators in Java are used to perform standard mathematical calculations on numeric values. They work with all of Java's numeric primitive types, including int, double, float, and long.

1. Addition (+)

Adds two operands together. When used with String values, + instead performs concatenation.

int sum = 8 + 4; // 12

2. Subtraction (-)

Subtracts the right operand from the left operand.

int diff = 10 - 3; // 7

3. Multiplication (*)

Multiplies two operands.

int product = 6 * 7; // 42

4. Division (/)

Divides the left operand by the right operand. Note that dividing two integers performs integer division, discarding any decimal remainder.

int result = 7 / 2; // 3, not 3.5
double result2 = 7.0 / 2; // 3.5

5. Modulus (%)

Returns the remainder after dividing the left operand by the right operand — useful for tasks like checking even/odd numbers.

int remainder = 10 % 3; // 1

Operator Precedence in Arithmetic

Multiplication, division, and modulus are evaluated before addition and subtraction, following standard mathematical order of operations, unless parentheses override that order.

int result = 5 + 3 * 2; // 11, not 16
  • + — addition (or String concatenation)
  • - — subtraction
  • * — multiplication
  • / — division
  • % — modulus (remainder)
Watch out for integer division — dividing two int values always produces an int result, so make sure at least one operand is a double or float if you need a decimal answer.

Master Java with Uncodemy

Hands-on training, live projects, and placement support in our Java Programming Course.

Explore the Course