/* Reverse.java CIS 160 David Klick 2009-12-01 Demonstration of Stack class to reverse words in a String. */ import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; public class Reverse { public static void main(String[] args) { Stack stk = new Stack(); System.out.print("Enter a line of text: "); StringTokenizer tok = new StringTokenizer( (new Scanner(System.in)).nextLine(), "- !~{}[]()*&^%$#@<>,.;':\"\\|/_+=?"); while (tok.hasMoreTokens()) stk.push(tok.nextToken()); while (!stk.isEmpty()) System.out.println(stk.pop()); } } /* Sample run: Enter a line of text: A stitch in time saves nine nine saves time in stitch A */