go to previous page   go to home page   go to next page hear noise highlighting
int quantity = 7;

quantity = 13;
System.out.println( "quantity holds: " + quantity );

Answer:

quantity holds:  13

The assignment statement replaced the value that was originally in quantity with the value 13.


Adding a Number to a Variable

Assume that extra already contains the value 5.

Extra with 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:

Do First

The result of the calculation is 7. The second step puts 7 into the variable value:

Do Second

QUESTION 15:

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 );

go to previous page   go to home page   go to next page