Java Array Sum sumMinMax(double[] values, int out[])

Here you can find the source of sumMinMax(double[] values, int out[])

Description

The sum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

License

Open Source License

Parameter

Parameter Description

Return

the sum of the values, out[0] min index [1] max

Declaration

public static double sumMinMax(double[] values, int out[]) 

Method Source Code

//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;
    }
}

Related

  1. summarizeIntegerArray(int[] numbers)
  2. summarizeNumbersAsString(int[] numbers)
  3. summation(double[] values)
  4. sumMaxK(double[] x, int k)
  5. summedDifference(int[][] matrix, short topX, short botX, short row)
  6. sumMult(double[] aArray1, double[] aArray2)
  7. sumNaive(final double... values)
  8. sumOf(int... values)
  9. sumOfArray(double[] array)