14) Write a complete Java class that uses the console window to prompt the user for a sentence to parse. Use the StringTokenizer class to echo the tokens back to the console.
What will be an ideal response?
```
import java.util.Scanner;
import java.util.StringTokenizer;
public class Parser
{
public static void main(String args[])
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a sentence and I'll display each word you entered: ");
String sentence = keyboard.nextLine();
//Parse the string into tokens and echo back to the user
StringTokenizer tk = new StringTokenizer(sentence, " ");
System.out.println("Here are the tokens: ");
while(tk.hasMoreTokens())
{
System.out.println(tk.nextToken());
}
}
}
```
You might also like to view...
When there are multiple actions in a macro, Access executes the actions according to an established priority list
Indicate whether the statement is true or false
As spreadsheet software, Microsoft Word provides a set of tools for entering and revising text, adding graphical elements such as color and tables, and then formatting and printing completed documents.
Answer the following statement true (T) or false (F)