Here you can find the source of maxIndex(double[] doubles)
Parameter | Description |
---|---|
doubles | the array of doubles |
public static int maxIndex(double[] doubles)
//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; } }