package Scanner;
//求多个数的和与平均数//
import java.util.Scanner;
public class 练习2 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int m =0;
double sum = 0;
while(scanner.hasNextDouble()){
double x = scanner.nextDouble();
//向x中输入数值
sum = sum+ x;//各个数值的和
m++;
System.out.println("你输入了第"+m+"个数据"+"当前结果为"+sum);
}
System.out.println(m+"个数的和为"+sum);
System.out.println(m+"个数的平均数为"+(sum/m));
}
}
练习2
最新推荐文章于 2024-05-07 14:26:59 发布