7-12 求一组数组中的平均数 (10 分)

输入10个整数,输出这10个整数的的平均数,要求输出的平均数保留2位小数

输入样例:

1 2 3 4 5 6 7 8 9 10

输出样例:

5.50

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int sum=0;
        for (int i=0;i<10;i++){
            int a=sc.nextInt();
            sum+=a;
        }
        double b=sum/10.000;
        System.out.printf("%.2f",b);
    }
}

 

你可能感兴趣的:(pta)