Search⌘ K

Arithmetic Operators

Explore the five basic arithmetic operators in Java and learn how they function with both int and double variables. Understand operator precedence, compound expressions, and the behavior of division and modulo operators. This lesson helps you confidently apply arithmetic operations and avoid common errors like division by zero.

Arithmetic operators are used for basic mathematical operations, such as the addition and subtraction of numbers. In Java, you can apply arithmetic operators to numeric type (such as int and double) variables. Java has a total of five arithmetic operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulo (%)

The first four are self-explanatory, and you should be well familiar with them from basic mathematics. Let’s look at the modulo operator in detail.

The modulo operator (%)

Remember how you used to do integer division in primary school? There are two things you get when you divide a number XX by YY: a quotient and a reminder. For example, if you divide ...