All About Operators
Statements can use mathematical expressions by employing the operators +, -, *, /, and %. You use these operators to crunch numbers throughout your Java programs.
An addition expression in Java uses the + operator, as in these statements:
double weight = 205;weight = weight + 10;
The second statement uses the + operator to set the weight variable equal to its current value plus 10. A subtraction expression uses the - operator:
weight = weight - 15;
This expression sets the weight variable equal to its current value minus 15.
A division expression uses the / sign:
weight = weight / 3;
This sets the weight variable to its current value divided by 3.
To find a remainder from a division expression, use the % operator (also called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access