hasNext()和hasNextLine()
hasNextLine()和nextLine()
hasNextLine()方法
同样看一些说明文档中对方法的描述:
如果在扫描器的输入中还有另外一行,就返回true,事实上同样没有返回fasle的情况,如果没有另外一行了,就会阻塞,等待你的输入。
两个容易出错的问题
问题1:hasNextLine() 和 next() 混用
首先看一下以下代码:如果启动代码后,在控制台输入hello回车
,会进入几次while循环的代码段中呢?
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNextLine()) {
String str = scan