现在的位置: 首页 > 综合 > 正文

Java03 InputLine

2013年03月26日 ⁄ 综合 ⁄ 共 586字 ⁄ 字号 评论关闭

It’s not easy for newcomer to learn java-application’s iostream.

Now from what I learn, I should creat a Reader to read what the user type, then create a BufferedReader to store the keywords.After doing that I can create String to readLine().

Here is the methods:

public static String inputLine() {

BufferedReader br = null;

Reader r = new InputStreamReader(System.in);

br = new BufferedReader(r);

String str = "";

try {

str = br.readLine();

} catch (IOException e) {

e.printStackTrace();

}

return str;

} 

By the way,When I want to get an int,I shoule convert the string.

Integer.parseInt(inputLine());

抱歉!评论已关闭.