int i = 0; float f = 0.0F; Scanner scanner = new Scanner(System.in); System.out.println("请输入整数:"); if(scanner.hasNextInt()){ i = scanner.nextInt(); System.out.println(); } System.out.println("请输入小数:"); if(scanner.hasNextFloat()){ f = scanner.nextFloat(); System.out.println(f); } scanner.close();