Java Array Min Value minOfArr(int[] arrInput)

Here you can find the source of minOfArr(int[] arrInput)

Description

minOfArr will return the minimum value in array.

License

Open Source License

Parameter

Parameter Description
arrInput array input

Return

minimum value

Declaration

public static int minOfArr(int[] arrInput) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w ww .  j  a  v a  2  s  .co  m*/
     * minOfArr will return the minimum value in array.
     *
     * @param arrInput array input
     * @return minimum value
     */
    public static int minOfArr(int[] arrInput) {
        int min = 0;
        for (int idx = 1; idx < arrInput.length; idx++) {
            if (arrInput[idx] != 99999) {
                min = arrInput[idx] < arrInput[min] ? idx : min;
            }
        }
        return min;
    }

    /**
     * minOfArr will return the minimum value in array with range.
     *
     * @param arrInput  array input
     * @param fromIndex starting index
     * @param toIndex   last index
     * @return minimum value within range
     */
    public static int minOfArr(int[] arrInput, int fromIndex, int toIndex) {
        int min = fromIndex;
        int bound = toIndex > arrInput.length ? arrInput.length - 1 : toIndex;
        for (int idx = fromIndex + 1; idx <= bound; idx++) {
            if (arrInput[idx] != 99999) {
                min = arrInput[idx] < arrInput[min] ? idx : min;
            }
        }
        return min;
    }

    /**
     * minOfArr will return the minimum value in array with range and exception.
     *
     * @param arrInput   array input
     * @param fromIndex  starting index
     * @param toIndex    last index
     * @param excludeInt integer excluded
     * @return minimum value within range
     */
    public static int minOfArr(int[] arrInput, int fromIndex, int toIndex, int excludeInt) {
        if (fromIndex == toIndex) {
            return fromIndex;
        } else {
            int min = fromIndex == excludeInt ? fromIndex + 1 : fromIndex;
            int bound = toIndex > arrInput.length ? arrInput.length - 1 : toIndex;
            for (int idx = fromIndex + 1; idx <= bound; idx++) {
                if (arrInput[idx] != 99999 && idx != excludeInt) {
                    min = arrInput[idx] < arrInput[min] ? idx : min;
                }
            }
            return min;
        }
    }
}

Related

  1. minMaxAvg(int[] arr)
  2. minMaxOverArraySubset(double[] array, Iterable subset, boolean min)
  3. minNonNeg(int... vals)
  4. minNum(Number iArr[])
  5. minOf(double[] da, double val)
  6. minOfArray(float[] array)
  7. minOfCol(int[][] matrixTable, int colBound)
  8. minOfSortedValues(double[] sortedValues)
  9. minOfSubRange(double[] xs, int start, int end)