revised: 10/05/03


Quiz on the do 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. What does the following print?

int count = 0;
do
{
  System.out.print( count +" ");
  count++  ; 
}
while ( count < 6 ); 

A.    0 1 2 3 4 5 6
B.    0 1 2 3 4 5
C.    1 2 3 4 5 6
D.    1 2 3 4 5

2. What does the following print?

int count = 10;
do
{
  System.out.print( count +" ");
  count++  ; 
}
while ( count < 6 ); 

A.    It prints nothing
B.    5
C.    6
D.    10

3. What does the following print?

int count = 10;
do
{
  System.out.print( count +" ");
  count--  ; 
}
while ( count >= 5 ); 

A.    10 9 8 7 6 5
B.    10 9 8 7 6 5 4
C.    9 8 7 6 5
D.    9 8 7 6 5 4

4. What does the following print?

int row = 1;
do
{
  int col = 1;
  do
  {
    System.out.print( "*" );
    col++ ; 
  }
  while ( col <= 5 );

  System.out.println();
  row++ ;
}
while ( row <= 3 ); 

A.   
***
***
***
***
B.   
***
***
***
***
***
C.   
*****
*****
*****
D.   
******
******
******

5. What does the following print?

int row = 1;
do
{
  int col = 1;
  do
  {
    System.out.print( "*" );
    col++ ; 
  }
  while ( col <= row );

  System.out.println();
  row++ ;
}
while ( row <= 3 ); 

A.   
*
**
***
B.   
***
**
*
C.   
******
*****
****
***
**
*
D.   
****
****
****

6. What type of loop is implemented with a do statement?

A.    top-driven loop
B.    bottom-driven loop
C.    off-by-one loop
D.    while loop

7. Is the do statement a necessary feature in Java?

A.    No--everything it does could be done with a while.
B.    No--but it would be exremely difficult without it.
C.    Yes--some loops can only be implemented with a do.
D.    Yes--without it one of the major control structures would be lost.

8. What are the branching statements in a programming language?

A.    Statements that affect the execution of loops.
B.    Statements like if that make choices.
C.    Statements that evaluate boolean expressions.
D.    Statements that are used to build classes.

9. What fact about a do loop is responsible for many program bugs?

A.    The do must be matched with a while.
B.    The do is not a good choice for a counting loop.
C.    The body of a do loop is always executed at least once.
D.    Using a do loop sometimes shortens a program.

10. Examine the following code fragment:

int j = 1;
do
{
  System.out.println( j );
  j++ ;
}
while ( j <= 3 ); 
Which of the following for loops does the same thing?

A.   
for ( int j=1; j < 3; j++ )
  System.out.println( j );
B.   
for ( int j=1; j <= 3; j++ )
  System.out.println( j );
C.   
for ( int j=0; j < 4; j++ )
  System.out.println( j );
D.   
for ( int j=0; j <= 3; j++ )
  System.out.println( j );

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


Click here

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.