import java.io.*;
import javagently.*;
import java.util.Stack;

public class Reverser {

  /* Testing the stack class  by J M Bishop  Jan 1997
   * -----------------------  Java 1.1
   *                          updated August 2000
   * Reads a sentence and reverses it using a stack.
   *Illustrates push, pop and empty in Java's Stack class.
   */

  public static void main (String args [])
    throws IOException {
    new Reverser();
  }

  Reverser () throws IOException {

    Stream in = new Stream (System.in);

    Stack S = new Stack();
    System.out.println("**** Testing the Stack class ****");
    System.out.println("Type in a sentence and end the input " +
       "(cntrl-D or cntrl-Z)");
    System.out.println("The original sentence is: ");

    while (true) {
      try {
        String word = in.readString();
        S.push(word);
      }
      catch (EOFException e) {break;}
    }

    System.out.println("The reversed sentence is:");
    while (!S.empty())
      System.out.print (S.pop()+" ");
    System.out.println();
  }
}
