Here you can find the source of calculateAverage(List
Parameter | Description |
---|---|
marks | a parameter |
public static Double calculateAverage(List<Double> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//w w w . j av a 2 s.c o m * Average of ints in array x. Adapted from: * http://stackoverflow.com/questions/10791568/calculating-average-of-an-array-list * null values are ignored, like R mean(..., na.rm= TRUE). * Returns Float.NaN if input list is empty or only nulls. You can check for Float.NaN * with Float.isNaN(x); * @param marks * @return */ public static Double calculateAverage(List<Double> list) { double sum = 0; long N = 0; if (!list.isEmpty()) { for (Double z : list) { if (z != null && !Double.isNaN(z)) { sum += z; N++; } } return (double) sum / N; } return Double.NaN; } }