A single = represents assignment and is typically read as "gets the value of". For example, x = 4 would be read as "x gets the value of 4". The right-hand side of the equals sign may be any expression that evaluates to the type denoted by the type of the variable specified on the left.
Mathematical Operators
-
+
- addition
-
-
- subtraction
-
*
- multiplication
-
/
- division
-
%
- remainder (modulo)
Java also provides
increment
and
decrement
operators.
++
indicates add 1 and
--
indicates subtract 1. The operator may appear on the right or the left of a variable name. On the left, we refer to pre-increment/decrement, and on the right we refer to post-increment/decrement. A pre-increment will first increment the variable and then execute the rest of the statement and a post-increment will first execute the statement and then increment the variable. An example follows:
|