computes the minimal value of a passed array - Android java.lang

Android examples for java.lang:array calculation

Description

computes the minimal value of a passed array

Demo Code


//package com.java2s;

public class Main {
    /**/*from w w  w  .j  ava 2 s  .  c  om*/
     * computes the minimal value of a passed array
     * @param _arr the array to get the minimum from
     * @return a double[] of size 2. the first index holds the minimum value of the passed array,
     * the second index holds the index where the minimum value is in the passed array
     */
    public static double[] min(double[] _arr) {
        double min = Double.MAX_VALUE;
        double minIdx = -1;

        for (int i = 0; i < _arr.length; i++) {
            if (_arr[i] < min) {
                min = _arr[i];
                minIdx = i;
            }
        }
        return new double[] { min, minIdx };
    }
}

Related Tutorials