Here you can find the source of sumMinMax(double[] values, int out[])
Double.NaN
if the designated subarray is empty.
Parameter | Description |
---|
public static double sumMinMax(double[] values, int out[])
//package com.java2s; /*//from www. ja v a2 s . co m * Copyright (c) 2006-2011 Karsten Schmidt * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * http://creativecommons.org/licenses/LGPL/2.1/ * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ public class Main { /** * The sum of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values, the input array * @return the sum of the values, out[0] min index [1] max */ public static double sumMinMax(double[] values, int out[]) { int max = 0; int min = 0, i; double sum = values[0]; int n = values.length; for (i = 1; i < n; i++) { sum += values[i]; if (values[i] > values[max]) max = i; if (values[i] < values[min]) min = i; } out[0] = min; out[1] = max; return sum; } }