creation: 8/13/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.   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 will read from a file called input.dat.

C:\MyDir> java AddUp      

4.   Is it possible for the readLine() method of a BufferedReader to read a blank line?

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

C:\MyDir> java Process    

6.   If a program reads integers from a text file, the characters in the file must be only an optional - or + followed by and the end of line character(s).

7.   Use the method with a string to create a new string with any beginning and ending spaces removed.

8.   If you use parseInt() with a string containing non-numeric characters you will get a exception at run time.

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

class Square
  public static void main ( String[] args ) throws 

    int value;

    String line;
    BufferedReader stdin = new BufferedReader(
        new InputStreamReader(   ) );

    System.out.println("Enter a number:");
    line   = stdin.readLine();
    value  = Integer.parseInt(    );

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

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 for file input. A good way to do this is to: This is a good idea because:

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.