[转]JAVA 读取键盘输入的字符串(string)or数字or单字符

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class IO{
   
    /** Creates a new instance of IO */
    public IO() {
    }
   
    /**
     * 读取输入的字符串
     */
    public static String getString() throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br= new BufferedReader(isr);
        String s = br.readLine();
        return s;
    }

    /**
     *读取一个字符
     */
    public static char getChar() throws IOException{
       String s = getString();
       return s.charAt(0);
     }
   
    /**
     * 读取键盘输入的数字
     */
    public static int getInt() throws IOException{
        String s = getString();
        return Integer.parseInt(s);
    }
}

posted @ 2010-07-26 15:53  梳子  阅读(3622)  评论(0编辑  收藏  举报