creation: 8/13/99; revised 01/15/06, 06/17/15

Fill in the Blanks

Instructions:   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.

1.   A program that normally gets its input from the keyboard can get its input from a file using ______ ________ .

2.   The input file must contain only bytes that represent characters and control characters. This type of file is called a ______ ________ .

3.   Fill in the blanks so that AddUp reads from a file called input.dat.

C:\MyDir> java AddUp __ ________ 

4.   Does the nextInt() method of Scanner allow integers with a leading + or -? ________

5.   Does the nextDouble() method of Scanner allow a leading + or -? ________

6.   Fill in the blanks so that Process will read input.dat and send its results to output.txt:

C:\MyDir> java Process < __________  > ________  

7.   If you use redirection to send output to a file will an existing file of the same name be overwritten? ____

8.   If you wish to append output to a file, what characters should you use to redirect output to it? ____

9.   Complete the following program so that it reads in some digits, converts them to an integer, then writes the square of the integer to output.

import java.util.Scanner;
class Square
  public static void main ( String[] args ) 

    int value;
    Scanner scan = new Scanner( ________);

    System.out.print("Enter a number: ");
    value  =  scan.________ ;

    System.out.println( "Square is: " + ________  );

10.   The previous program can be used just as it is for input from a file. However it would be nice to remove the prompt, which is useless when input is from a file A good way to do this is to change the prompt into a ________ by placing the characters ____ in front of it.

End of the Exercise. If you want to do it again, click on "Refresh" in your browser window.

go to home page