Java Arithmetic Operators
In Java, an Operator is a symbol used to perform operations, usually mathematical like addition or multiplication. In these lessons we will explore some of the most common operators used in Java.
Every Java program you will write will do a lot of mathematical calculating. Arithmetic operators allow programmers to specify how numerical values within variables should be evaluated.
The most common arithmetic operators, known as binary operators, are used to add, subtract, multiply and divide numbers.
In Java, these arithmetic operators are:
+ for addition to add two numbers together, for example 10 + 2 would return 12.
– for subtraction to subtract one number from another number, for example 10 – 2 would return8.
* for multiplication to multiple one number by another number, for example 10 * 2 would return 20.
/ for division to divide one number by another number, for example 10 / 2 would return 5.
% for modulo to find the remainder of a division, for example 10 % 2 would return 0 since there is no remainder.
To see these in action, imagine we have two variables with the following values: numA=10 and numB=3:
What you have learnt
In this lesson you have learnt the basics of the most common Arithmetic operators in Java. These operators will enable your programs to perform useful mathematics calculations.