⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reverser.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 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 + -