Arithmetic Operators

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 99 by 44, you get a quotient of 22 and a remainder of 11.

Get hands-on with 1200+ tech skills courses.