Here you can find the source of maxIndex(float[] arr)
Parameter | Description |
---|---|
arr | array of floats |
public static int maxIndex(float[] arr)
//package com.java2s; public class Main { /**/* ww w. ja v a 2 s.c o m*/ * Returns the index to the smallest value in the array * * @param arr array of floats * @return the index */ public static int maxIndex(float[] arr) { float max = Float.MIN_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } /** * Returns the index to the smallest value in the array * * @param arr array of ints * @return the index */ public static int maxIndex(int[] arr) { int max = Integer.MIN_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } /** * Returns the index to the smallest value in the array * * @param arr array of longs * @return the index */ public static int maxIndex(long[] arr) { long max = Long.MIN_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } /** * Returns the index to the smallest value in the array * * @param arr array of bytes * @return the index */ public static int maxIndex(byte[] arr) { long max = Byte.MIN_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } /** * Returns the index to the smallest value in the array * * @param arr array of shorts * @return the index */ public static int maxIndex(short[] arr) { short max = Short.MIN_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } /** * Returns the index to the smallest value in the array * * @param arr array of doubles * @return the index */ public static int maxIndex(double[] arr) { double max = -Double.MAX_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return index; } }