creation: 08/06/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. No grade is calculated for this exercise.


1.   When an if-else is contained inside of a loop body, the if-else statement is called a if.


2.  Fill in the blanks so that the boolean expression is true when num is ODD:
( num   == 1 )


3.  Fill in the blanks in the following
5! == * * * *



4.   The following program is supposed to write out the values 1!, 2!, 3!, 4!, up to 10! . Fill in the blanks.

class Factorial
{  
  public static void main (String[] args)
  {
    int fact =  ; // current factorial value 
    int count =  ;// loop control  
    while ( count  10 ) 
    {
       fact  = fact *   ; 
       System.out.println( count +"! is " + fact );  
       count = count +   ; 
    }
  }
}

5.   The following program asks the user for two integers, X and Y and then adds up all the integers (inclusive) between them. Fill in the blanks.

class AddRange
{  
  public static void main (String[] args)   
  {
    BufferedReader stdin = 
            new BufferedReader( new (  System.in ) );  
    int sum =  ; // current sum 
    System.out.println("Enter start of range:");
    int start = Integer.( inData );  

    System.out.println("Enter end of range:");
    int end   = Integer.( inData );  

    int count =  ;  
 
    while ( count  end ) 
    {
       sum   = sum +   ; 
       count = count +   ; 
    }

    System.out.println("sum is:" + sum);

  }
}

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.