标签:printf col NPU 计算 键盘 pre 结束 system string
package com.company; import java.util.*; public class Main { public static void main(String arg[]) { Scanner input = new Scanner(System.in); double sum = 0; int m = 0; while (input.hasNextDouble()) { double x=input.nextDouble(); m++; sum+=x; } System.out.printf("%d个数的和为%f\n",m,sum); System.out.printf("%d个数的平均值为%f\n",m,sum/m); } }
【Java】用键盘输入若干数字,以非数字字符结束,计算这些数的和和平均值
标签:printf col NPU 计算 键盘 pre 结束 system string
原文地址:https://www.cnblogs.com/HGNET/p/14584469.html