Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying individual text  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to everyone,
I am almost finished with a program except for creating a loop which will display all the words entered by a user and captured by the Keyboard.readString. I have enough code to display the first word but have been unsuccessful with a code that will display the words individually.
For example: I must go to the store.
token : |I|
token : |must|
token : |go|
Here is my code so far:

st = new StringTokenizer (entry);
while (st.hasMoreTokens())
String token = st.nexttoken();
System.out.println ("token : |" + token + "|");
Thank you very, very much for your help.
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Norman!
Other than your code example not being complete, and that you've misspelled the nextToken() method, your logic and syntax looks about correct. Was the misspelled method name perhaps the problem?
On a side note, something that I very much appreciated being pointed at when just starting to learn to program in Java (last week) is the Java 2 SE API documentation. It details all of the constructors and methods available in each class definition.
Note that the J2SE API documentation doesn't include the Keyboard class you mentioned as it's not part of the official Java libraries (API). I'd guess that you received Keyboard from a book, tutorial, or instructor. I would expect that the originator of the Keyboard class also has JavaDocs available of the same format and style of the J2SE API documentation linked above.
[ March 13, 2004: Message edited by: Dirk Schreckmann ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!