Scanner 进阶
package com.yyr.base.scanner;
import java.util.Scanner;
public class Demo05 {
public static void main(String[] args) {
//我们要输入多个数字,并且求其总和平均数,没输入一个数字用回车符确认,通过输入非数字结束输入并输出执行结果
Scanner scanner = new Scanner(System.in);
double sum=0;
int m=0;
while (scanner.hasNextDouble()){
double v = scanner.nextDouble();
m=m+1;
sum=sum+v;
System.out.println("你输入了第"+m+"个数字"+"和为"+sum);
}
System.out.println(m+"个数的和为"+sum);
System.out.println(m+"个数的平均值为"+(sum/m));
scanner.close();
}
}
标签:进阶,scanner,sum,System,Scanner,out
From: https://www.cnblogs.com/yyrldp/p/16797867.html