测试代码
public class Text {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s = input.nextLine();
System.out.println(s);
s = input.next();
System.out.println(s);
}
}
运行结果:
测试代码:
public class Text {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s = input.next();
System.out.println(s);
s = input.nextLine();
System.out.println(s);
输出结果
总结: next 以空格和回车作为结束符,并且会过滤掉前面的字符, nextLine 只以回车作为结束符
next只要字,nextLine除了回车什么都要