|
Reverse |
|
1 // joi/examples/Reverse.java
2 //
3 //
4 // Copyright 2003 Bill Campbell and Ethan Bolker
5
6 import java.util.ArrayList;
7
8 /**
9 * Reverse the order of lines entered from standard input.
10 */
11
12 public class Reverse
13 {
14
15 /**
16 * Read lines typed at the terminal until end-of-file,
17 * saving them in an ArrayList.
18 *
19 * Then print the lines in reverse order.
20 */
21
22 public static void main( String[] args )
23 {
24 Terminal t = new Terminal();
25 ArrayList list = new ArrayList();
26 String line;
27
28 while ((line = t.readLine()) != null ) {
29 list.add(line);
30 }
31
32 for (int i = list.size()-1; i >= 0; i--) {
33 line = (String)list.get(i);
34 t.println( line );
35 }
36 }
37 }
38
|
Reverse |
|