您的位置:首页 > 编程语言 > Java开发

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

2010-07-26 15:53 495 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐