Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;

public class Main {
    /**
     * @param nums Any descendant of Number (Integer, Short, Double, Float, etc)
     * @return The mean of the number, or Double.NaN if the list is empty.
     */
    public static double mean(Collection<? extends Number> nums) {
        if (nums == null || nums.isEmpty()) {
            return Double.NaN;
        }
        double sum = 0.0;
        for (Number n : nums) {
            sum += n.doubleValue();
        }
        return sum / nums.size();
    }
}