
2.4 Expressions and Arithmetic Operators 75
2.4.7 Shortcut Operators
A common operation in programming is adding 1 to a number (incre-
menting) or subtracting 1 from a number (decrementing). For example, if
you were counting how many data items the user entered, every time you
read another data item, you would add 1 to a count variable.
Because incrementing or decrementing a value is so common in program-
ming, Java provides shortcut operators to do this:
++ and ––. (Note that
there are no spaces between the two plus and minus signs.) The statement
count++;
adds 1 to the value of count, and the statement
count– –;
subtracts 1 from the value of count.