public class ScannnerDemo { public static void main(String[] args){ Scanner scann = new Scanner(System.in); double sum = 0; int m = 0; while(scann.hasNextDouble()) { double x = scann.nextDouble(); m = m+1; sum = sum+x; } System.out.println(m+"个数的和是"+sum); System.out.println(m+"个数的平均数是"+sum/m);}}问题描述:我把while换成if 如图结果为:可while与if逻辑上不一样吗?为毛执行结果这么大差别。
添加回答
举报
0/150
提交
取消