public class ScannerDemo01 {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
double sum = 0;//和
int b = 0;//输出了多少个数
System.out.println("请输入:");
while (a.hasNextDouble()) {
double c = a.nextDouble();
b++;
sum = sum + c;
System.out.println("你输出了第" + b + "个数,当前和为:" + sum);
System.out.println("请输入:");
}
System.out.println("总和=" + sum);
System.out.println("输出了" + b + "个数字");
System.out.println("平均数是:" + sum / b);
a.close();
}
}
标签:scanner,sum,System,用户,println,交互,public,out From: https://www.cnblogs.com/ly123dcom/p/17858571.html