Java Array Max Value argMax(int[] a)

Here you can find the source of argMax(int[] a)

Description

arg Max

License

Open Source License

Parameter

Parameter Description
a a parameter

Return

the index of a maximum value in a

Declaration

public static int argMax(int[] a) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * OscaR is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version./* w  w w.ja  v  a2 s.  c o  m*/
 *   
 * OscaR is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License  for more details.
 *   
 * You should have received a copy of the GNU Lesser General Public License along with OscaR.
 * If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
 ******************************************************************************/

public class Main {
    /**
     *
     * @param a
     * @return  the index of a maximum value in a
     */
    public static int argMax(int[] a) {
        int v = Integer.MIN_VALUE;
        int ind = -1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] > v) {
                v = a[i];
                ind = i;
            }
        }
        return ind;
    }
}

Related

  1. argmax(double[] array, boolean naturalNumbers)
  2. argmax(double[] weights)
  3. argmax(final double[] vec)
  4. argmax(float[] args)
  5. argmax(int[] a)
  6. argmax(int[] array)
  7. argmax(int[] array)
  8. argmax(int[] input)