11_用户交互Scanner
01_用户交互Scanner
- next()不能得到带空格的字符串
- nextLine()可以得到带空格字符串
- hasNextInt()等方法判断输入格式
//创建一个scanner对象,接收键盘信息
Scanner scanner = new Scanner(System.in);
//注意区分next()和nextLine()方法
//String str = scanner.next();
String str = scanner.nextLine();
System.out.println("输入内容为:" + str);
//IO流的类注意关闭
scanner.close();
小提示
- IO流的类注意关闭。

浙公网安备 33010602011771号