Scanner练习
import java.util.Scanner;
public class Scanner02 {
public static void main(String[] args) {
//创建扫描器对象,用于接收键盘数据
Scanner scanner = new Scanner(System.in);
//从键盘接收数据
int i = 0;
float f = 0.0F;
System.out.println("请输入整数!");
//如果....那么
if(scanner.hasNextInt()){
i = scanner.nextInt();
System.out.println("输入的整数是:"+i);
} else {
System.out.println("输入的不是整数!");
}
if(scanner.hasNextFloat()){
f = scanner.nextFloat();
System.out.println("输入的小数是:"+f);
} else {
System.out.println("输入的不是小数!");
}
scanner.close();
}
}