// 帮你弄了一个 你可以去试试
import java.util.Scanner;
public class JsAvg {
public static void main(String[] args) {
System.out.println("请依次输入数字用空格分隔,输入0结束");
Scanner in = new Scanner(System.in);
double n, sum = 0, count = 0;
while (true) {
n = in.nextDouble();
if (n == 0.0)
break;
sum += n;
count += 1;
}
System.out.println("平均数为:" + sum / count);
}
}
温馨提示:答案为网友推荐,仅供参考