next up previous
Next: Increment and decrement operators Up: Unit 04 Previous: Numeric overflow

Combined assignment operators

Consider the following fragment of a Java program:

int sum, a, salary, increase;
sum = sum + a;
salary = salary * increase;

It can be abbreviated as follows:

sum += a;
salary *= increase;

In general, the assignment:

x = x operator expression
can be abbreviated as:
x operator= expression

For each of the arithmetic operators +, -, *, /, %, there is the corresponding combined assignment operator +=, -=, *=, /=, %=.


next up previous
Next: Increment and decrement operators Up: Unit 04 Previous: Numeric overflow