Here you can find the source of minIndex(double[] a)
Parameter | Description |
---|---|
a | a parameter |
public static final int minIndex(double[] a)
//package com.java2s; /*/* w w w . j av a2 s .co m*/ * Copyright 2014 Jon N. Marsh. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Returns the index of the minimum value in array a. If {@code a==null} or * {@code a.length==0}, the return value is {@code -1}. If several elements * have the same value equal to the minimum value of {@code a}, the returned * value is the index of the first instance of the minimum value. * * @param a * @return index of minimum value or {@code -1} if {@code a.length==0} or * {@code a==null} */ public static final int minIndex(double[] a) { int index = -1; if (a != null && a.length != 0) { double min = a[0]; index = 0; for (int i = 1; i < a.length; i++) { if (a[i] < min) { min = a[i]; index = i; } } } return index; } /** * Returns the index of the minimum value in array a. If {@code a==null} or * {@code a.length==0}, the return value is {@code -1}. If several elements * have the same value equal to the minimum value of {@code a}, the returned * value is the index of the first instance of the minimum value. * * @param a * @return index of minimum value or {@code -1} if {@code a.length==0} or * {@code a==null} */ public static final int minIndex(float[] a) { int index = -1; if (a != null && a.length != 0) { float min = a[0]; index = 0; for (int i = 1; i < a.length; i++) { if (a[i] < min) { min = a[i]; index = i; } } } return index; } }