next():
1.一定要读取到有效字符后才可以结束输入.
2. 对输入有效字符之前遇到的空白,next()方法会自动将其去掉.
3. 只有输入有效字符后才将其后面输入的空白作为分隔符或者结束符.
4. next() 不能得到带有空格的字符串.
```java
Scanner scanner = new Scanner(System.in);
System.out.println("请输入:");
if(scanner.hasNext()){
String next = scanner.next();
System.out.println(next);
}
scanner.close();
运行输出:
请输入:
hello wrod!
hello
nextLine():
1. 以Enter为结束符,也就是说 nextLine()方法返回的输入回车之前的所有字符.
2. 可以获得空白.
if(scanner.hasNextLine()){
String next = scanner.nextLine();
System.out.println(next);
}
请输入:
hello word
hello word