001package algs13;
002import stdlib.*;
003/* ***********************************************************************
004 *  Compilation:  javac Reverse.java
005 *  Execution:    java Reverse
006 *  Dependencies: Stack.java StdOut.java StdIn.java
007 *
008 *  Read a sequence of integers from standard input and print them
009 *  in reverse order.
010 *
011 *  % java  java Reverse
012 *  1 2 3 4 5
013 *  5
014 *  4
015 *  3
016 *  2
017 *  1
018
019 *************************************************************************/
020
021public class XReverseStdIn {
022        public static void main(String[] args) {
023                //StdIn.fromString ("1 2 3 4 5");
024                StdIn.fromString ("10 20 30 40 50");
025
026                Stack<Integer> stack = new Stack<>();
027                while (!StdIn.isEmpty()) {
028                        int i = StdIn.readInt();
029                        stack.push(i);
030                }
031                while (! stack.isEmpty()) {
032                        int i = stack.pop ();
033                        StdOut.println(i);
034                }
035        }
036}