平均数与求和
import java.util.Scanner;public class scanner03 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);//和double sum = 0;//输入的个数int count =0;System.out.println("请输入需要进行计算的数字:");while (scanner.hasNextDouble()){double x = scanner.nextDouble();//sum接收每一次,输入的x的值sum += x;//每接收一个数字,count的值自增1count++;System.out.println("你输入的第"+count+"个数字"+"当前的和为:"+sum);}System.out.println("输入的数字和为:" + sum);System.out.println("输入的数字平均数为:" + (sum/count));scanner.close();}
}