scanner
-
实现用户与键盘交互,接收键盘数据
-
scanner.next()识别到内容后,空格后内容就不接受
package com.sund.scanner; import java.util.Scanner; public abstract class Demo01 { public static void main(String[] args) { //从键盘接收数据 Scanner scanner = new Scanner(System.in); System.out.println("请输入:"); String str = scanner.next(); System.out.println("输出的内容是:" +str); //请输入: //hello world! //输出的内容是:hello scanner.close(); } }
-
scanner.nextLint()接收所有内容
package com.sund.scanner; import java.util.Scanner; public class Demo02 { public static void main(String[] args) { //从键盘接收数据 Scanner scanner = new Scanner(System.in); System.out.println("请输入:"); String str = scanner.nextLine(); System.out.println("输出内容为:" + str); //请输入: //hello world! //输出内容为:hello world! scanner.close(); } }