stackdemo.java

来自「Java学习源代码检索系统免费版」· Java 代码 · 共 40 行

JAVA
40
字号
//==============================================================
// StackDemo.java - Demonstrate Stack (extended LinkedList) class
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import Stack;
 
class StackDemo {
 public static void main(String args[]) {
  String s;
  try {
   Stack fruitStack = new Stack();
   fruitStack.push("Apples");
   fruitStack.push("Peaches");
   fruitStack.push("Pumpkin");
// Enable following to force an unchecked exception
//   fruitStack.removeFirst();
// Peek at top of stack 
   s = (String)fruitStack.peek();
   System.out.println("\nTop of stack = " + s);  
// Pop all objects from stack
   System.out.println("\nPopping all objects:");
   while (!fruitStack.isEmpty()) {
    s = (String)fruitStack.pop();
    System.out.println(s);
   }
// Enable following to force a checked exception
//   s = (String)fruitStack.pop();
  } catch (StackEmptyException e) {
   System.out.println("*** Error: " + e.getMessage());
  }
 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?