Java Array Max Value maxIndex(int[] a)

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

Description

max Index

License

Open Source License

Declaration

public static int maxIndex(int[] a) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    public static int maxIndex(int[] a) {
        int currentMax = a[0];
        int currentMaxIndex = 0;
        for (int i = 1; i < a.length; i++) {
            if (a[i] > currentMax) {
                currentMax = a[i];//from  w w  w . j  av  a  2 s .  co  m
                currentMaxIndex = i;
            }
        }
        return currentMaxIndex;
    }

    public static int maxIndex(double[] a) {
        double currentMax = a[0];
        int currentMaxIndex = 0;
        for (int i = 1; i < a.length; i++) {
            if (a[i] > currentMax) {
                currentMax = a[i];
                currentMaxIndex = i;
            }
        }
        return currentMaxIndex;
    }
}

Related

  1. maxIndex(final double[] a)
  2. maxIndex(final double[] values)
  3. maxIndex(float[] arr)
  4. maxIndex(float[] from, int start)
  5. maxIndex(float[] x)
  6. maxIndex(int[] array)
  7. maxIndex(int[] from)
  8. maxIndex(int[] list)
  9. maxIndex(int[] shape)