Java Reference
In-Depth Information
9.1. Arithmetic Operations
There are several binary arithmetic operators that operate on any of the
primitive numerical types:
addition
+
subtraction
-
multiplication
*
division
/
remainder
%
You can also use unary
-
for negation. The sign of a number can be in-
verted with code like this:
val = -val;
For completeness there is also a unary
+
, as in
+2.0
.
The exact actions of the binary arithmetic operators depend on the types
of operands involved. The following sections look at the different rules for
integer and floating-point arithmetic.