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

Correct Answer Is:


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

Correct Answer Is:


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

Correct Answer Is:


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

Correct Answer Is:


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

Correct Answer Is:


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

Correct Answer Is:


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.

Correct Answer Is:


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.

Correct Answer Is:


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.

Correct Answer Is:


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 );

Correct Answer Is:


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