package scanner;标签:11,scanner,System,2022,println,out,输入,小数 From: https://www.cnblogs.com/RUI2022/p/16851925.html
import java.util.Scanner;
public class Demo03 {
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("输入的不是整数");
}
System.out.println("请输入小数:");
if (scanner.hasNextFloat()){
f=scanner.nextFloat();
System.out.println("输出小鼠为:"+f);
}else {
System.out.println("输入不是小数");
}
scanner.close();
}
}