输入整数或者小数-2022-11-2

package scanner;

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();
}
}
posted @ 2022-11-02 18:14  Rui2022  阅读(64)  评论(0编辑  收藏  举报