creation: 08/04/99


Fill in the Blanks

Instructions:   This is an ungraded fill-in-the-blank exercise. Each question consists of a sentence with one or two words left out. A button represents the missing word(s). For each question, think of the word or phrase that should fill each blank, then click on the buttons to see if you are correct.


This exercise reviews loops and the while statement.

1.   When a mechanical machine repeatedly does something in performing its work it contains a . When a program repeatedly executes the same statements it contains a .


2.  Fill in the following blanks to show the syntax of a while statement:

while   ( )
      

3.  The statement immediately following the while is called the It can be a   by including several statements between braces { and }.


4.   What three things must be coordinated in order for a loop to run correctly?

  1. The must be set up correctly.
  2. The in the while statement must be correct.
  3. The in the loop body must be correct.

5.   The condition of the while must evaluate to each time before the loop body executes.


6.   An variable (usually an int) that is used to control how a loop works is called a .


7.   The following program is supposed to write out the integers 1, 2, 3, and 4. Decide what should go in the blanks.

class Counter
{  
  public static void main (String[] args)
  {
    int count ;
    count =  ;  
    while ( count  4 )  
    {
       System.out.println( count );  
        count = count +   ;  
    }
  }
}

8.   The following program is supposed to write out the integers 10, 11, 12, 13, 14, and 15. Decide what should go in the blanks.

class Counter2
{  
  public static void main (String[] args)
  {
    int j ;

    j =  ;  
    while ( j <  )  
    {
      System.out.println( j );  
      j = j +   ;  
    }
  }
}

9.   The following program is supposed to write out the integers 0, 2, 4, 6. Decide what should go in the blanks.

class Counter3
{  
  public static void main (String[] args)
  {
    int j ;
    j =  ;  
    while ( j <=  )  
    {
      System.out.println( j );  
      j = j +   ;  
    }
  }
}

10.   The following program is supposed to write out the integers 2, 1, 0, -1 . Decide what should go in the blanks.

class Counter3
{  
  public static void main (String[] args)
  {
    int count ;
    count =  ;  
    while ( count >=  )  
    {
      System.out.println( count );  
      count = count -   ;  
    }
  }
}

End of the Exercise. If you want to do it again, click on "Refresh" in your browser window. Click here to go back to the main menu.