O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required