// Reversing a sequence of words by using a Stack import java.io.*; import java.util.*; class reverse1 { public static void main (String[] args) throws IOException { BufferedReader stdin; stdin = new BufferedReader (new InputStreamReader (System.in)); System.out.print ("Type a sequence of words: "); StringTokenizer str = new StringTokenizer(stdin.readLine()); Stack s = new Stack(); while (str.hasMoreTokens()) s.push(str.nextToken()); // fill the stack while (! s.empty()) System.out.print (s.pop() + " "); // empty the stack } }