public static void main(String[] args) throws IOException{
System.out.println("请输入一个小写字母:");
int read=System.in.read();
}
和public static void main(String[] args){
Scanner scan=new Scanner(System.in);
string i=scan.nextline();
....
}
这两种输入有什么区别啊,新人求教啊,
System.out.println("请输入一个小写字母:");
int read=System.in.read();
}
和public static void main(String[] args){
Scanner scan=new Scanner(System.in);
string i=scan.nextline();
....
}
这两种输入有什么区别啊,新人求教啊,
if (hasNextPattern == linePattern())
return getCachedResult();
clearCaches(); String result = findWithinHorizon(linePattern, 0);
if (result == null)
throw new NoSuchElementException("No line found");
MatchResult mr = this.match();
String lineSep = mr.group(1);
if (lineSep != null)
result = result.substring(0, result.length() - lineSep.length());
if (result == null)
throw new NoSuchElementException();
else
return result;
}
System.in.read()读取的是你输入字符串中的第一个字节值
而Scanner scan=new Scanner(System.in);
public Scanner(InputStream source) {
this(new InputStreamReader(source), WHITESPACE_PATTERN);
}
Scanner内部会将其包装为字符流
scan.nextline();读取的就是你输入的一行字符串