4.13 Increment and Decrement Operators
Java provides two unary operators (summarized in Fig. 4.14) for adding 1 to or subtracting 1 from the value of a numeric variable. These are the unary increment operator, ++
, and the unary decrement operator, --. A program can increment by 1 the value of a variable called c
using the increment operator, ++
, rather than the expression c = c + 1
or c+= 1
. An increment or decrement operator that’s prefixed to (placed before) a variable is referred to as the prefix increment or prefix decrement operator, respectively. An increment or decrement operator that’s postfixed to (placed after) a variable is referred to as the postfix increment or postfix decrement operator, respectively.
Fig. 4.14
Operator | Sample ... |
---|
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.