StringTokenizer and File Input

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

A good answer might be:

StringTokenizer st = new StringTokenizer( time, ":AP", true )

StringTokenizer and File Input

Usually the input for a program comes from a file or from user input. StringTokenizer is useful in breaking this input into individual pieces of data. For example, say that a program is to add up integers, and that there may be several integers per line of input:

java addUp
Please enter the data:
12  8  5  32
The sum is: 57

This is more convenient for the user than requiring one integer per line. Here is an outline of a program that does this:

import java.util.* ;
import java.io.* ;

public class AddUp
{

  public static void main ( String[] args ) throws IOException
  {
    StringTokenizer tok;
    int sum = 0;

    BufferedReader inData = new BufferedReader 
        ( new InputStreamReader( System.in ) );

    System.out.println("Please enter the data:" );
    String inString = inData.readLine();
    tok = new StringTokenizer( _________________ );

    while ( tok._____________________() )
    {
      String intSt = tok._______________() ;
      int data     = Integer.____________( intSt );
      sum         += data;
    }

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

QUESTION 20:

Fill in the blanks.