Using arithmetic operators should include outlining the available operators in Java and their possible uses:
Operator |
Use |
Description |
+ |
op1 + op2 |
Adds op1 and op2 |
- |
op1 - op2 |
Subtracts op2 from op1 |
* |
op1 * op2 |
Multiplies op1 by op2 |
/ |
op1 / op2 |
Divides op1 by op2 |
% |
op1 % op2 |
Computes the remainder of dividing op1 by op2 |
These short-cut operators increment or decrement a number by one:
Operator |
Use |
Description |
++ |
op++ |
Increments op by 1; evaluates to the value of op before it was incremented |
++ |
++op |
Increments op by 1; evaluates to the value of op after it was incremented |
-- |
op-- |
Decrements op by 1; evaluates to the value of op before it was decremented |
-- |
--op |
Decrements op by 1; evaluates to the value of op after it was decremented |
These are the Java programming language's other arithmetic operators:
Operator |
Use |
Description |
+ |
+op |
Promotes op to int if it is a byte, short, or char |
- |
-op |
Arithmetically negates op |