revised: 10/04/03

# on Variables and Assignment

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. Which one of the following is a reserved word?

 A.    apple B.    7up C.    grandTotal D.    boolean

2. Which one of the following is NOT a correct variable name?

 A.    2bad B.    zero C.    theLastValueButOne D.    year2000

3. Which one of the following declarations is NOT correct?

 A.    double duty; B.    float loan; C.    boolean value = 12; D.    int start = 34, end = 99;

4. What does the following program output?

class question4
{
public static void main ( String[] args )
{
int unitCost = 8;
int items    = 5;
System.out.println("total cost: " + (unitCost * items) );
}
}

 A.    total cost: + 40 B.    total cost: 8*5 C.    total cost: 40 D.    "total cost: " 40

5. Which of the following shows the syntax of an assignment statement?

 A.    variableName  =  expression; B.    expression  =  expression; C.    expression  =  variableName; D.    dataType  =  variableName;

6. What are the two steps that take place when an assignment statement is executed?

 A.    (i) Evaluate the Expression, and (ii) Store the value in the variable. B.    (i) Store the value in the variable, and (ii) Evaluate the Expression. C.    (i) Reserve memory , and (ii) fill it with a number. D.    (i) Evaluate the variable, and (ii) store the results.

7. What is an expression?

 A.    The same thing as a statement. B.    An expression is a list of statements that make up a program C.    An expression is a combination of literals, operators, variables, and parentheses used to calculate a value. D.    An expression is a number expressed in digits.

8. Which one of the following expressions is NOT correct?

 A.    5 + 4 B.    (5 * 4)/2 C.    (-12 + (13 + 7)/2 ) * 4 D.    -12 + (13 + 7)/2 ) * 4

9. Which of the following expressions is incorrect?

 A.    (34 - 86) / 3 B.    (34 - 86) / -3 C.    34 - 86) / (23 - 3 ) D.    ( (34 - 86) / (23 + 3 ) )

10. What is the value of the following expression:

(2 - 6) / 2 + 9

 A.    7 B.    8 C.    9 D.    10

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

If you have 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 to clear the old answers.