隨筆-144  評論-80  文章-1  trackbacks-0

          package com.faintbear;
          import java.io.*;


          class Input{
               //Read a Sring from kedboard
                  public static String getString()
                  {
                      String string="";
                      BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
                      try
                      {
                          string=br.readLine();
                      }
                      catch(IOException iox)
                      {
                          System.err.println(iox);
                      }
                  return string;
                  }
                 
                  // read a char from keyboard
                  public static char getChar()throws java.io.IOException
                  {
                          char cookie;

                          while(true){
                                  String string=getString();//Reads the next line of text from the input stream

                                  //Check the input
                                  if (string.length()>1)
                                  {
                                      System.err.println("Sorry,You should input a character,");
                                      System.err.println("Please input again");
                                      continue;
                                  }
                                  else {
                                          cookie=string.charAt(0) ;
                                          return cookie;
                                  }
                          }
                  }
                 
                 
                  //read a double number from keyboard
                  public static double getDouble( ) 
                  {
                      double cookie;

                      while(true)
                      {
                              String string = getString();
                              try
                              {
                                  cookie=Double.parseDouble(string);
                                  return cookie;
                              }
                              //Check the number
                              catch(NumberFormatException nfe)
                              {
                                  System.err.println("Sorry,this is not a double number,plz input again");
                                  continue;
                              }
                      }
                     
                  }
                 
                  //Read a int number from keyboard
                  public static int getInt( ) 
                  {
                      int cookie;
                      while(true)
                      {
                          String string = getString();
                          try
                          {
                              cookie=Integer.parseInt(string);
                              return cookie;
                          }
                          //Check the input number
                          catch(NumberFormatException nfe)
                          {
                              System.err.println("Sorry,this is not a integer number,plz input again");
                              continue;
                          }
                      }
                  }
                 
                  //Read a float number from keyboard
                  public static float getFloat()
                  {
                      float cookie;
                      while(true)
                      {
                          String string = getString();
                          try
                          {
                              cookie=Float.parseFloat(string);
                              return cookie;
                          }
                          //Check the input number
                          catch(NumberFormatException nfe)
                          {
                              System.err.println("Sorry,this is not a float number,plz input again");
                              continue;
                          }
                      }
                     
                  }

          }

           

           

          package com.faintbear;
          import com.faintbear.Input;
          public class Class1
          {
           public static void main(String[] args)
           {
            System.out.println("請輸入數據");
            System.out.println("******************");
            int kk=Input.getInt();
            System.out.println("l1====="+kk);
           }
          }

          posted on 2005-03-30 23:35 小力力力 閱讀(319) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 九江县| 巩义市| 阿坝| 萨迦县| 靖安县| 冕宁县| 信阳市| 武隆县| 凉山| 闽清县| 濉溪县| 紫金县| 儋州市| 梓潼县| 襄樊市| 开封县| 沈丘县| 新昌县| 佳木斯市| 龙门县| 文成县| 津南区| 封开县| 多伦县| 什邡市| 绩溪县| 若尔盖县| 永修县| 布尔津县| 焦作市| 岳普湖县| 南汇区| 盐津县| 苏尼特右旗| 北辰区| 明溪县| 赤壁市| 长阳| 军事| 昌江| 绥江县|