# Quiz 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.");

``````

 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 = 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.

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

``````
int sum = 94;
if ( sum < 20 )
{
System.out.print("Under ");
System.out.println("the limit.");
}
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.

5. 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.

6. 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.

7. 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.

8. A sequence of statements contained within a pair of braces ("{" and "}") is called a:

 a.    block b.    blob c.    branch d.    brick

9. 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 `

10. Say that value has a 19 stored in it, and that extra has a 25 stored in it. Evaluate (to true or false) each of the following expressions:

``````
value <= extra     extra < value      value > -25     value  >=  extra
``````

 a.    ` true    false    true    false` b.    ` true    true    true    false` c.    `false    false    true    false` d.    `false    false    true    true `

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

(If you have just returned here from another page, or re-loaded this page, you will need to click again on each of your choices for the grading program to work.)