Java Array Max Value argmax(int[] input)

Here you can find the source of argmax(int[] input)

Description

Returns the index of the largest element in an array.

License

Open Source License

Parameter

Parameter Description
input a nonempty array of unique elements

Declaration

public static int argmax(int[] input) 

Method Source Code

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

public class Main {
    /**//from  www  .  j  ava2s . c o  m
     * Returns the index of the largest element in an array.
     * @param input a nonempty array of unique elements
     */
    public static int argmax(int[] input) {
        int i = input.length - 1;
        int currentMaximum = input[i];
        int currentArgmax = i;
        while (i >= 0) {
            if (input[i] > currentMaximum) {
                currentMaximum = input[i];
                currentArgmax = i;
            }
            i++;
        }
        return currentArgmax;
    }
}

Related

  1. argmax(float[] args)
  2. argMax(int[] a)
  3. argmax(int[] a)
  4. argmax(int[] array)
  5. argmax(int[] array)
  6. arrayMax(double maxVal, double[] vals)
  7. arrayMax(double[] arr)
  8. arrayMax(double[] x)
  9. arrayMax(final int[] array)