关于java.util.Scanner的注意

next()和nextLine()的区别

二者都是针对String类型的读取。next()是以空格符和换行符为读取标志;nextLine()只以换行符为读取标志,可以读取一整行内容。

        Scanner scanner = new Scanner(System.in);
        String nextlineStr = scanner.nextLine();
        System.out.println("scanner.nextLine()得到:" + nextlineStr);		
        String nextStr = scanner.next();
        System.out.println("scanner.next()得到:" + nextStr);

  结果:

原文地址:https://www.cnblogs.com/tlyx/p/6810161.html