求数组所有元素的平均值

public class TestDemo1{
    public static double avg(int[]array){
        double sum=0.0;
        for (int i = 0; i <array.length ; i++) {
           sum+=array[i];
        }return sum/array.length;
    }
    public static void main(String[] args) {
       int[]array={434,6678,4234,845,977};
        double a=avg(array);
        System.out.println(a);
    }
}

你可能感兴趣的:(java)