-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest2.java
More file actions
36 lines (35 loc) · 970 Bytes
/
Copy pathTest2.java
File metadata and controls
36 lines (35 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.sinllychen.string;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
/**
* 编写一个类,实现简单的栈操作。数据的操作按照先进后出的顺序。成员函数为pop,push,size,full.empty.print等等
* @author sinllychen
*
*/
public class Test2 {
public static void main(String[] args)
{
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
Stack<Integer> mystack=new Stack<Integer>();
while(true)
{
try
{
System.out.println("请输入进栈数据(以输入字符串结束):");
int n=Integer.parseInt(input.readLine());
mystack.push(n);
}
catch(Exception p)
{
break;
}
}
System.out.println("出栈数据:");
while(!mystack.isEmpty())
{
System.out.print(mystack.pop()+" ");
}
}
}