package cn.itcast_02;

import java.util.Scanner;

/*
* 基本格式:
* public boolean hasNextXxx():判断是否是某种类型的元素。
* public Xxx nextXxx():获取该元素。
*
* 举例:用int类型的方法举例
* public boolean hasNextInt():
* public int nextInt():
*
* 注意:
* InputMismatchException:输入的和你想要的不匹配。
*/
public class ScannerDemo {
public static void main(String[] args) {
// 创建对象
Scanner sc = new Scanner(System.in);

// 获取数据
if (sc.hasNextInt()) {
int i = sc.nextInt();
System.out.println("i:" + i);
} else if (sc.hasNextFloat()) {
float f = sc.nextFloat();
System.out.println("f:" + f);
} else if (sc.hasNextBoolean()) {
boolean b = sc.nextBoolean();
System.out.println("b:" + b);
} else if (sc.hasNext()) {
String s = sc.next();
System.out.println("s:" + s);
} else {
System.out.println("您好,您当前输入的数据无效!");
}
}

}