Java Array Max Value maxIndex(double[] doubles)

Here you can find the source of maxIndex(double[] doubles)

Description

Returns index of maximum element in a given array of doubles.

License

Open Source License

Parameter

Parameter Description
doubles the array of doubles

Return

the index of the maximum element

Declaration

public static  int maxIndex(double[] doubles) 

Method Source Code

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

public class Main {
    /**//from ww  w  .  j  av a2s .c o  m
     * Returns index of maximum element in a given
     * array of doubles. First maximum is returned.
     *
     * @param doubles the array of doubles
     * @return the index of the maximum element
     */
    public static /*@pure@*/ int maxIndex(double[] doubles) {

        double maximum = 0;
        int maxIndex = 0;

        for (int i = 0; i < doubles.length; i++) {
            if ((i == 0) || (doubles[i] > maximum)) {
                maxIndex = i;
                maximum = doubles[i];
            }
        }

        return maxIndex;
    }

    /**
     * Returns index of maximum element in a given
     * array of integers. First maximum is returned.
     *
     * @param ints the array of integers
     * @return the index of the maximum element
     */
    public static /*@pure@*/ int maxIndex(int[] ints) {

        int maximum = 0;
        int maxIndex = 0;

        for (int i = 0; i < ints.length; i++) {
            if ((i == 0) || (ints[i] > maximum)) {
                maxIndex = i;
                maximum = ints[i];
            }
        }

        return maxIndex;
    }
}

Related

  1. maxIndex(double[] arr)
  2. maxIndex(double[] arr)
  3. maxIndex(double[] array)
  4. maxIndex(double[] array)
  5. maxIndex(double[] arrays)
  6. maxIndex(double[] doubles)
  7. maxIndex(double[] doubles, int begin, int end)
  8. maxIndex(double[] v)
  9. maxIndex(double[] value)