packagecom.shang.scanner;importjava.util.Scanner;publicclassDemo05{publicstaticvoidmain(String[] args){//输入多个数字,求平均数和总和,每输入一个数字用回车确认,非数字结束输入Scanner scanner =newScanner(System.in);double sum =0;//计算输入了多少个数字int m =0;//通过循环判断是否还有输入,并在里面每一次进行求和----判断输入是否为非数字while(scanner.hasNextDouble()){double x = scanner.nextDouble();
m++;
sum += x;}System.out.println("和:"+sum);System.out.println("平均数:"+(sum/m));
scanner.close();}}