Here you can find the source of geometricMean(double[] nums)
Parameter | Description |
---|---|
nums | the numbers to average |
public static double geometricMean(double[] nums)
//package com.java2s; /*/* ww w . ja va 2 s . com*/ Copyright (C) 2010, 2011 Constantine Lignos This file is a part of CATS. CATS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. CATS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CATS. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Return the geometric mean of an array of numbers. * @param nums the numbers to average * @return their geometric mean */ public static double geometricMean(double[] nums) { double prod = 1.0; for (double num : nums) { prod *= num; } return Math.pow(prod, 1.0 / (double) nums.length); } }