I am making a program which would have the user enter a sentence and following that, the app would break the String into sub-strings where spaces are what break the original string up.
import java.util.StringTokenizer;
public class whitespace {
public static void main(String[] args) {
String text = "supervisors signature tom hanks";
int tokenCount; //number of words
int idx=0; // index
String words[]=new String [500]; // space for words
StringTokenizer st=new StringTokenizer(text); // split text into segements
tokenCount=st.countTokens();
while (st.hasMoreTokens()) // is there stuff to get?
{
words[idx]=st.nextToken();
idx++;
}
}
I have this code thus far and while it works fine as a regular Java program, the while loop seems to cause the app to go into an infinite loop. Any ideas?