Arithmetic Operators
Let's look at Java's arithmetic operators in more detail.
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 by : a quotient and a reminder. For example, if you divide by , you get a quotient of and a remainder of .
Get hands-on with 1400+ tech skills courses.