O'Reilly logo

Java Garage by Eben Hewitt

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

Arithmetic Operators

These are +, *, -, and / for addition, multiplication, subtraction, and division. That's about it.

There is also the modulus operator, which looks like this: %. If you can't remember modulus, which actually comes in handy with surprising frequency, it is used to return the remainder of performing a division operation.

For example, 10 % 3 = 1, because 10 divided by 3 is 3 (which we don't care about) with a remainder of 1 (which is what we care about when we use modulus).

There's one more thing: you can use a special shorthand in combination with any of the arithmetic operators (excluding modulus) to modify an existing value.

Say you have a variable of type int called x and its value is 0, and you want to add 1 to it. You can ...

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