revised: 10/04/03, 10/29/2012

# on the if statement

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. How many choices are possible when using a single if-else statement?

A.    1

B.    2

C.    3

D.    4

2. What does the following code fragment write to the monitor?

``````
int sum = 14;
if ( sum < 20 )
System.out.print("Under ");
else
{
System.out.print("Over  ");
System.out.println("the limit.");
}

``````

(Notice that the program has changed from the previous question!)

A.    Under

B.    Over

C.    Under the limit.

D.    Over the limit.

3. What does the following code fragment write to the monitor?

``````
int sum =  7;
if ( sum > 20 )
{
System.out.print("You win ");
}
else
{
System.out.print("You lose  ");
}

System.out.println("the prize.");

``````

(Notice that the program has changed from the previous question!)

A.    You win

B.    You lose

C.    You win the prize.

D.    You lose the prize.

4. What does the following code fragment write to the monitor?

``````
int sum =  21;
if ( sum != 20 )
System.out.print("You win ");
else
System.out.print("You lose  ");

System.out.println("the prize.");

``````

(Notice that the program has changed from the previous question!)

A.    You win

B.    You lose

C.    You win the prize.

D.    You lose the prize.

5. Evaluate (to true or false) each of the following expressions:

```14 <= 14     14 < 14      -9 > -25     -25  >  -9
```

A.    `true     true     true     true`

B.    `true     false     false     false`

C.    `true     false     true     true `

D.    `true     false     true     false `

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.