平均数与求和
import java.util.Scanner;
public class scanner03 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//和
double sum = 0;
//输入的个数
int count =0;
System.out.println("请输入需要进行计算的数字:");
while (scanner.hasNextDouble()){
double x = scanner.nextDouble();
//sum接收每一次,输入的x的值
sum += x;
//每接收一个数字,count的值自增1
count++;
System.out.println("你输入的第"+count+"个数字"+"当前的和为:"+sum);
}
System.out.println("输入的数字和为:" + sum);
System.out.println("输入的数字平均数为:" + (sum/count));
scanner.close();
}
}
标签:count,scanner,求和,平均数,sum,System,println,out
From: https://www.cnblogs.com/GXEndeavor/p/18639243