Arithmetic operators

Arithmetic operators are the most widely used operators of the Java language simply because they’re used to compute numbers.
There are four different arithmetic operators, namely:

+ (addition)
– (subtraction)
* (multiplication)
/ (division)
% (modulo)
– (unary minus)

Arithmetic operators can be used on any primitive data type except for boolean.

Here are some examples of how to use them:

Modulo returns the remainder when the first operand is divided by the second operand an integral number of times.
The unary minus simply converts a positive number to a negative (or a negative number to positive, like -(-5)).

It’s important to remember that if one of the operands is a floating-point number, floating-point arithmetic will be used.
If not then integer arithmetic will be used, so output of the above code will look like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.