Java Array Min Value minmax(int[] values)

Here you can find the source of minmax(int[] values)

Description

minmax

License

Eclipse Public License

Declaration

public static int[] minmax(int[] values) 

Method Source Code

//package com.java2s;
/* ******************************************************************************
 * //  w  w w  .  j  a  v a 2 s  .  com
 * This file is part of JMH
 * 
 * License:
 *   EPL: http://www.eclipse.org/legal/epl-v10.html
 *   LGPL 3.0: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *   See the LICENSE file in the project's top-level directory for details.
 *
 * **************************************************************************** */

public class Main {
    public static int[] minmax(int[] values) {
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int value : values) {
            if (value < min) {
                min = value;
            }
            if (value > max) {
                max = value;
            }
        }
        return new int[] { min, max };
    }

    public static double[] minmax(double[] values) {
        double min = Integer.MAX_VALUE;
        double max = Integer.MIN_VALUE;
        for (double value : values) {
            if (value < min) {
                min = value;
            }
            if (value > max) {
                max = value;
            }
        }
        return new double[] { min, max };
    }
}

Related

  1. minList(int[] listA, int[] listB)
  2. minLocation(double[] list)
  3. minmax(double[] a)
  4. minMax(float... values)
  5. minMax(float[] array)
  6. minMax(int[] values)
  7. minmax(String args[], boolean minimum)
  8. minMaxAvg(int[] arr)
  9. minMaxOverArraySubset(double[] array, Iterable subset, boolean min)