int quantity = 7; quantity = 13; System.out.println( "quantity holds: " + quantity );
quantity holds: 13
The assignment statement replaced the value that was
originally in quantity
with the value 13.
Assume that extra
already contains the value 5.
Here is another statement:
value = extra + 2;
The statement will be performed in two steps (as always).
The first step performs the calculation extra + 2
by first copying the 5 from extra
,
and then adding 2 to it:
The result of the calculation is 7.
The second step puts 7 into the variable value
:
What will the following program print out:
// Example assignment statements int extra, value; extra = 5; value = extra + 2; System.out.println( "value now holds: " + value );