day 12
package com.ljs.scanner;
import java.util.Scanner;
public class Demo02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("使用nextLine方式接受:");
if (scanner.hasNextLine()){
String str = scanner.nextLine();
System.out.println("输出的内容为:"+str);
scanner.close();
}
}
}
-
next():
-
一定要读取到有效字符下可以结束输入。
-
对输入有效字符之前遇到的空白,next()方法会自动将其去掉。
-
只有输入有效字符后才将其后面输入的空白作为分隔符或者结束符。
-
next()不能得到带有空格的字符串。
-
-
nextLine():
-
以Enter为结束符,nextLine()方法返回的是输入回车之前的所有字符;
-
可以获得空白。

浙公网安备 33010602011771号