publicstaticvoidmain(String[] args){
Scanner scanner =newScanner(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();}
publicstaticvoidmain(String[] args){
Scanner scanner =newScanner(System.in);//和double sum =0;//计算输入了多少个数字int m =0;//通过循环判断是否还有输入,并且在里面的求和做一个统计while(scanner.hasNextDouble()){double v = scanner.nextDouble();
m = m+1;//m++
sum += v;
System.out.println("你输入了"+m+"个数据,和为sum"+sum);}
System.out.println(m+"个数的和为"+sum);
System.out.println(m+"个数的平均值是"+(sum/m));
scanner.close();}