import java.util.StringTokenizer; public class StringTokens{ public String reverseWords(String sentence){ StringTokenizer tokens = new StringTokenizer(sentence); String result = ""; while(tokens.hasMoreTokens()){ String[] t = new String[10]; for(int j = 0; j < sentence.length(); j++){ t[j] = tokens.nextToken(); } for(int k = sentence.length()-1; k >= 0; k--){ result = result + t[k]; } } return result; } }
The code above compiles but then gives me an error saying "java.util.NoSuchElementException" I believe referring to line 12t[j] = tokens.nextToken();