工作小驛

          Ninja!

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            103 Posts :: 0 Stories :: 36 Comments :: 0 Trackbacks
          import java.io.*;

          public class KeyboardInput{

          private final BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
          public final synchronized int readInteger(){
          String input="";
          int value=0;
          try{
          input=in.readLine();
          }
          catch (IOException e){}
          if(input!=null){
          try{
          value=Integer.parseInt(input);
          }
          catch(NumberFormatException e){}
          }
          return value;
          }

          public final synchronized long readLong(){
          String input="";
          long value=0L;
          try{
          input=in.readLine();
          }
          catch (IOException e){}
          if(input!=null){
          try{
          value=Long.parseLong(input);
          }
          catch(NumberFormatException e){}
          }
          return value;
          }

          public final synchronized double readDouble(){
          String input="";
          double value=0.0D;
          try{
          input=in.readLine();
          }
          catch (IOException e){}
          if(input!=null){
          try{
          value=Double.parseDouble(input);
          }
          catch(NumberFormatException e){}
          }
          return value;
          }

          public final synchronized float readFloat(){
          String input="";
          float value=0.0F;
          try{
          input=in.readLine();
          }
          catch (IOException e){}
          if(input!=null){
          try{
          value=Float.parseFloat(input);
          }
          catch(NumberFormatException e){}
          }
          return value;
          }

          public final synchronized char readCharacter(){
          char c=;
          try{
          c=(char)in.read();
          }
          catch (IOException e){}
          return c;
          }

          public final synchronized String readString(){
          String s="";
          try{
          s=in.readLine();
          }
          catch (IOException e){}
          if(s==null){
          s="";
          }
          return s;
          }
          }
          posted on 2007-10-06 08:17 王君 閱讀(371) 評論(0)  編輯  收藏 所屬分類: J2SE
          主站蜘蛛池模板: 嵊州市| 霍林郭勒市| 汾西县| 昭苏县| 巴青县| 百色市| 黄大仙区| 巴塘县| 新巴尔虎左旗| 杭锦旗| 淄博市| 景德镇市| 贡觉县| 昌都县| 新源县| 宜君县| 塘沽区| 科尔| 大连市| 东港市| 通化县| 尼玛县| 资源县| 牡丹江市| 安远县| 罗城| 峨眉山市| 武冈市| 秀山| 龙海市| 新闻| 宁乡县| 武安市| 泰和县| 荔波县| 库伦旗| 鲁山县| 开平市| 和平区| 本溪市| 晋江市|