A good answer might be:

java TokenTester "val = 12+8"
val

=

12
+
8

Ignoring Spaces

Notice that the spaces are returned as well as the other delimiters and tokens. This might not be quite what you want. You might like to ignore spaces completely and use only "=+-" as delimiters. The following does that:

import java.util.* ;

public class TokenTester
{

  public static void main ( String[] args )
  {
    StringTokenizer tok;
    if ( args.length > 0 )
    {
      tok = new StringTokenizer( args[0], "=+-", true );  // no space

      while ( tok.hasMoreTokens() )
        System.out.println( tok.nextToken().trim() );
    }
  }
}

Now nextToken() returns the strings "val ", "=", " 12", "+", and "8". The trim() method trims spaces off both ends of these strings.

QUESTION 18:

An program expects a string that contains the current time, such as "9:23AM" or "12:45PM". Call the string time. How should the StringTokenizer be constructed?