[Java 12 IO] Scanner 输入数据类
输入数据类
package com.qunar.basicJava.javase.io; import java.util.Scanner; /** * Author: libin.chen@qunar.com Date: 14-6-6 09:14 */ /** Scanner 输入数据类 */ public class ScannerDemo01 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);// 可接受任何的 inputStream 来构造 String str = scanner.next(); System.out.println("输入的数据为 : " + str); if (scanner.hasNextInt()) { int i = scanner.nextInt(); System.out.println("输入的数字为 : " + i); } } }