average a double type array - Java java.lang

Java examples for java.lang:Math Algorithm

Description

average a double type array

Demo Code


//package com.java2s;

public class Main {
    public static double average(double a[]) {
        double sum = 0;
        for (int i = 0; i < a.length; ++i) {
            sum += a[i];/*from w  w w  . j  ava 2  s .  co m*/
        }
        return sum / a.length;
    }
}

Related Tutorials