It’snoteasyfornewcomertolearnjava-application’siostream.
NowfromwhatIlearn,IshouldcreataReadertoreadwhattheusertype,thencreateaBufferedReadertostorethekeywords.AfterdoingthatIcancreateStringtoreadLine().
Hereisthemethods:
publicstaticStringinputLine(){
BufferedReaderbr=null;
Readerr=newInputStreamReader(System.in);
br=newBufferedReader(r);
Stringstr="";
try{
str=br.readLine();
}catch(IOExceptione){
e.printStackTrace();
}
returnstr;
}
Bytheway,WhenIwanttogetanint,Ishouleconvertthestring.
Integer.parseInt(inputLine());
努力爱一个人。付出,不一定会有收获;