java:I/O 根据用户输入反馈信息

时间:2014-06-10 20:15:03   收藏:0   阅读:250
bubuko.com,布布扣
import java.io.*;
class userInputIO{
            //Java中成员变量有默认初始化,也就是如果不显式设置初始值的话就会被初始化为其类型的默认值(0、false、null等)。 
        private BufferedReader bufferedReader;
        public userInputIO(){
            //System.in用户的输入做成BufferedReader流
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }
        public String getInputLine(){
            String inputLine = null;
            try {
                inputLine = bufferedReader.readLine(); //用户输入数据之后,按下回车键,该行代码即可读取到用户的输入
            } catch (IOException e) {
                e.printStackTrace();
            }
            return inputLine;
        }
        

}
bubuko.com,布布扣

 

bubuko.com,布布扣
public class Test {
    public static void main(String[] args) {
        userInputIO userInputIO =new userInputIO();
        while(true){
            String input = userInputIO.getInputLine();
            System.out.println(input);
        }

    }

}
bubuko.com,布布扣

 

java:I/O 根据用户输入反馈信息,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!