www.baidu.com

JavaCode--我爱你,芳儿

JavaStudy--我爱你,芳儿

关于模拟堆栈的java程序

InterfaceTest Class
 1 import java.io.*;
 2 public class InterfaceTest 
 3 {
 4     private static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
 5     public static void main(String[] args)
 6     {
 7         
 8         Stack stack = new Stack();
 9         
10         String s1 = "";
11 
12         while(!s1.equals("exit"))
13         {
14 
15             System.out.println("please input int:");
16             try
17             {
18                 s1 = stdIn.readLine();
19                 if(s1.equals("exit"))
20                     break;
21 
22             }
23             catch(Exception e2)
24             {
25                 System.out.print(e2);
26             }
27             int i1;
28             try
29             {
30                 i1 = Integer.parseInt(s1);
31                 
32             }
33             catch(Exception e3)
34             {
35                 System.out.println(e3);
36                 continue;
37             }            
38             stack.input(i1);
39         }
40         while(stack.top > 0)
41         {
42             System.out.println(stack.getout());
43         }
44 
45     }
46 }
47 
48 

Stack Class
 1 
 2 public class Stack implements Access
 3 {
 4     private int array[] = new int[80];
 5     
 6     int top = 0;
 7 
 8     public void input(int i)
 9     {
10         array[top++= i;
11     }
12     public int getout()
13     {
14         return array[--top];
15     }
16 }
17 


 

芳儿宝贝.我爱你

posted on 2007-12-04 23:03 wǒ愛伱--咾婆 阅读(233) 评论(0)  编辑  收藏 所属分类: JavaCode


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

公告

芳儿宝贝.我爱你


黑客基地
http://www.hackbase.com
全球最大的黑客门户网站


 最近在读的书:

常用链接

留言簿(1)

随笔分类(37)

JavaCode

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜