created 11/24/99

Quiz on Increment and Decrement

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.



1. What is the most common operation performed by a program?

a.    Adding integer one to an integer variable.
b.    Floating point division.
c.    Object construction.
d.    Internet access.

2. What two steps are performed when an assignment statement is executed?

a.   
  1. The expression on the right of the "=" is evaluated, "using" all the variables it contains.
  2. The result of evaluation is assigned to the variable on the left of the "=".
b.   
  1. All appropriate variables are incremented or decremented.
  2. The result is assigned to the variable on the left of the "=".
c.   
  1. All appropriate variables are incremented.
  2. All appropriate variables are decremented.
d.   
  1. The arithmetic expression is evaluated and assigned to the variable on the left of the "=".
  2. Variables are auto-incremented or auto-decremented.

3. What is the meaning of variable++   ?

a.    Add one to the variable.
b.    Add one to the variable after its current value has been used.
c.    Add one to the variable before using its value.
d.    Double the value in the variable.

4. What does the following program output to the monitor:

int value = 0;
int count = 1;

value = count++ ;

System.out.println("value: "+ value " + count: " + count ); 

a.    value: 0 count: 0
b.    value: 0 count: 1
c.    value: 1 count: 1
d.    value: 1 count: 2

5. What does the following program output to the monitor:

int value = 0;
int count = 1;

value = ++count ;  /* note change from previous */

System.out.println("value: "+ value " + count: " + count ); 

a.    value: 0 count: 1
b.    value: 1 count: 1
c.    value: 1 count: 2
d.    value: 2 count: 2

6. What is the output of the following:

int a = 0;
int b = 10;

a = --b ;

System.out.println("a: " + a + "  b: " + b ); 

a.    a: 9 b:11
b.    a: 10 b: 9
c.    a: 9 b:9
d.    a: 0 b:9

7. What is the output of the following program:

double w = 12.5 ;
w *= 2 ;

System.out.println( " w is " + w  ); 

a.    w is 12.5
b.    w is 13.5
c.    w is 25.0
d.    w is 2

8. Which of the answers does the same thing as the following:

value += sum++ ;

a.   
value = value + sum;
sum = sum + 1;
b.   
sum = sum + 1;
value = value + sum;
c.   
value = value + sum;
d.   
value = value + ++sum;

9. Fill in the blank so that wages is divided by two.

wages ____________ 2 ;

a.    *=
b.    -=
c.    =/
d.    /=

10. Are the auto-increment and auto-decrement operators (++ and -- ) an essential part of the Java language?

a.    No---any program that uses them could be written without them.
b.    No---they are not fundamental, but some programs could not be written without them.
c.    Yes---some programs can't be written unless these operators are available.
d.    Yes---because adding or subtracting one can't be done without them.

The number you got right:       Percent Correct:       Letter Grade:   

Click here (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)