日期:2014-05-20 浏览次数:20797 次
public String 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系统预设的为BufferedInputStream
System.in.read()读取的是你输入字符串中的第一个字节值
而Scanner scan=new Scanner(System.in);
public Scanner(InputStream source) { this(new InputStreamReader(source), WHITESPACE_PATTERN); }