Java03 InputLine

来源:互联网 发布:京东小程序源码 编辑:程序博客网 时间:2024/04/30 08:40

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());

原创粉丝点击