📄 reverser.java
字号:
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -