import org.apache.commons.math.stat.*;
import org.apache.commons.math.stat.descriptive.*;

public class testApacheCommosMath {
    
    public double[] inputArray = {1.3, 5.44, 5.6523, -0.9232, -11.334, 5.523443};
    public double mean = 0.0;
    public DescriptiveStatistics stats = new DescriptiveStatistics();

    testApacheCommosMath() { 

 for (int i = 0; i < this.inputArray.length; i++) {
     this.stats.addValue(this.inputArray[i]);
 }
 this.mean = this.stats.getMean();
    }
    
    public static void main(String[] args) {
 testApacheCommosMath tesObj1 = new testApacheCommosMath();
 System.out.println(tesObj1.mean);
    }
}

P.S.: I say it silly because it takes lots of line to give you a simple mean

Advertisements