An program expects a String that contains the current time, such as "9:23AM" or "12:45PM" or "4:00 AM"
StringTokenizer st = new StringTokenizer( time, ":AP", true )
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 );
}
}