creation: 08/06/99; revised 10/12/08


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 calculate 1*2*3*4*5*6*7*8*9*10 . Fill in the blanks.

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

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

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

    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.

go to home page