Java Array Min Value minIndex(int[] ints)

Here you can find the source of minIndex(int[] ints)

Description

Returns index of minimum element in a given array of integers.

License

Open Source License

Parameter

Parameter Description
ints the array of integers

Return

the index of the minimum element

Declaration

public static  int minIndex(int[] ints) 

Method Source Code

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

public class Main {
    /**// w  w  w . j ava 2 s. c om
     * Returns index of minimum element in a given
     * array of integers. First minimum is returned.
     *
     * @param ints the array of integers
     * @return the index of the minimum element
     */
    public static /*@pure@*/ int minIndex(int[] ints) {

        int minimum = 0;
        int minIndex = 0;

        for (int i = 0; i < ints.length; i++) {
            if ((i == 0) || (ints[i] < minimum)) {
                minIndex = i;
                minimum = ints[i];
            }
        }

        return minIndex;
    }

    /**
     * Returns index of minimum element in a given
     * array of doubles. First minimum is returned.
     *
     * @param doubles the array of doubles
     * @return the index of the minimum element
     */
    public static /*@pure@*/ int minIndex(double[] doubles) {

        double minimum = 0;
        int minIndex = 0;

        for (int i = 0; i < doubles.length; i++) {
            if ((i == 0) || (doubles[i] < minimum)) {
                minIndex = i;
                minimum = doubles[i];
            }
        }

        return minIndex;
    }
}

Related

  1. minIndex(float[] arr)
  2. minIndex(float[] vals)
  3. minIndex(float[] xs)
  4. minIndex(int[] array)
  5. minIndex(int[] from)
  6. minIndex(int[] values)
  7. minIndex(Number[] array)
  8. minIndexGreaterThan(final double[] array, final double p)
  9. minInRowIndex(double[][] M, int row)