/****************************************************************************** * Compilation: javac Reverse.java * Execution: java Reverse * Dependencies: Stack.java StdOut.java StdIn.java * * Read a sequence of integers from standard input and print them * in reverse order. * * % java Reverse * 1 2 3 4 5 * 5 * 4 * 3 * 2 * 1 ******************************************************************************/ public class Reverse { public static void main(String[] args) { Stack stack = new Stack(); while (!StdIn.isEmpty()) { stack.push(StdIn.readInt()); } for (int i : stack) { StdOut.println(i); } } }