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ǒ愛伱--咾婆 閱讀(264) 評論(0)  編輯  收藏 所屬分類: JavaCode

          導航

          統(tǒng)計

          公告

          芳兒寶貝.我愛你


          黑客基地
          http://www.hackbase.com
          全球最大的黑客門戶網站


           最近在讀的書:

          常用鏈接

          留言簿(1)

          隨筆分類(37)

          JavaCode

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 淅川县| 香河县| 改则县| 龙海市| 集贤县| 阿勒泰市| 鄯善县| 济源市| 静宁县| 红桥区| 泰顺县| 淳化县| 本溪| 五台县| 谢通门县| 巴林左旗| 莲花县| 余姚市| 平陆县| 泰来县| 依安县| 阿瓦提县| 滦南县| 加查县| 滨州市| 缙云县| 石嘴山市| 晴隆县| 双鸭山市| 永年县| 通城县| 休宁县| 多伦县| 高要市| 贵州省| 阳原县| 鹤岗市| 新泰市| 息烽县| 天气| 沧州市|