6.15stacktest.java
来自「JAVA程序设计的源代码」· Java 代码 · 共 23 行
JAVA
23 行
import java.util.*;
class StackTest
{
public static void main(String []args)
{
Stack stack1=new Stack(); //构造一个空堆栈stack1
try{
stack1.push(new Integer(0)); //向栈中逐一压入元素
stack1.push(new Integer(1));
stack1.push(new Integer(2));
stack1.push(new Integer(3));
stack1.push(new Integer(4));
System.out.println((Integer)stack1.pop()); //打印后将元素逐一弹出
System.out.println((Integer)stack1.pop());
System.out.println((Integer)stack1.pop());
System.out.println((Integer)stack1.pop());
System.out.println((Integer)stack1.pop());
}
catch(EmptyStackException e){ }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?