Calculate average or take in an ArrayList as a parameter to a function

前端 未结 2 1656
野性不改
野性不改 2021-02-11 04:50

Is there a built-in method to calculate the average of an integer ArrayList?

If not, can I make a function that will do that by taking in the name of the ArrayList and r

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-11 05:06

    If you want to computer later one more than the average I propose Colt library developed at CERN which supports many statistic functions. See BinFunctions1D and DoubleMatrix1D. An alternative (with a recent code basis) may be commons-math:

    DescriptiveStatistics stats = new DescriptiveStatistics();
    for( int i = 0; i < inputArray.length; i++)
    {
        stats.addValue(inputArray[i]);
    }
    double mean = stats.getMean();
    

提交回复
热议问题