java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

文本方式键盘输入

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56605
import java.io.*;
public class KeyInput{
  static InputStreamReader isr=new InputStreamReader(System.in);
  static BufferedReader br=new BufferedReader(isr);
  public static int readInt(){
        int i=0;
        try{
            i=Integer.parseInt(br.readLine());
        }
        catch(Exception e){
            System.out.println(e);
        }
        return i;
  }
  public static  float readFloat() {
      float f=0.0f;
      try{
          f=Float.parseFloat(br.readLine());
      }
      catch(Exception e){
          System.out.println(e);
      }
      return f;
  }
  public static  double readDouble() {
      double d=0.0;
      try{
          d=Double.parseDouble(br.readLine());
      }
      catch(Exception e){
          System.out.println(e);
      }
      return d;
  }
  public static  String readString() {
      String s="";
      try{
          s=br.readLine();
      }
      catch(Exception e){
          System.out.println(e);
      }
      return s;
  }
  public static  boolean readBoolean() {
      String s="";
      try{
          s=br.readLine();
      }
      catch(Exception e){
          System.out.println(e);
      }
      if (s.toUpperCase().equals("TRUE"))
          return true;
      else
          return false;
  }
  public static void main(String args[]){

      System.out.print("Please input an integer number:");
      System.out.println("Your input is "+KeyInput.readInt());
      System.out.print("Please input a float number:");
      System.out.println("Your input is "+KeyInput.readFloat());
      System.out.print("Please input a double number:");
      System.out.println("Your input is "+KeyInput.readDouble());
      System.out.print("Please input a string:");
      System.out.println("Your input is "+KeyInput.readString());
      System.out.print("Please input a boolean value:");
      System.out.println("Your input is "+KeyInput.readBoolean());
  }
}

posted on 2009-06-10 21:40 rrong_m 阅读(126) 评论(0)  编辑  收藏

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜