Here you can find the source of mean(List extends Number> nums, int start, int size)
Parameter | Description |
---|---|
nums | The numbers to get the mean of. |
start | The index to start taking the mean at |
size | The number of elements to include in the mean. |
Parameter | Description |
---|---|
IllegalArgumentException | If anything is weird (null or zero list), zero size. |
public static double mean(List<? extends Number> nums, int start, int size)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { /**/*from w ww. j a va 2 s . c o m*/ * Calculate the mean of a range in list of numbers. * * @param nums The numbers to get the mean of. * @param start The index to start taking the mean at * @param size The number of elements to include in the mean. * * @throws IllegalArgumentException If anything is weird (null or zero list), zero size. * * @return The mean */ public static double mean(List<? extends Number> nums, int start, int size) { if (nums == null || nums.size() == 0 || start < 0 || start >= nums.size() || size <= 0 || start + size > nums.size()) { throw new IllegalArgumentException(); } double mean = 0; for (int i = start; i < start + size; i++) { mean += nums.get(i).doubleValue(); } return (mean / size); } /** * Calculate the mean of a list of numbers. * * @param nums The numbers to get the mean of. * * @throws IllegalArgumentException If anything is weird (null or zero list). * * @return The mean. */ public static double mean(List<? extends Number> nums) { if (nums == null || nums.size() == 0) { throw new IllegalArgumentException(); } return mean(nums, 0, nums.size()); } }