Java Array Min Value min(double[] numbers)

Here you can find the source of min(double[] numbers)

Description

min

License

Open Source License

Declaration

public static int min(double[] numbers) 

Method Source Code

//package com.java2s;
// are made available under the terms of the Eclipse Public License v1.0

public class Main {
    public static int min(double[] numbers) {
        if (numbers.length == 0)
            return -1;
        double min = numbers[0];
        int id = 0;
        for (int i = 1; i < numbers.length; i++) {
            double n = numbers[i];
            if (n < min) {
                min = n;// ww w.  j av  a2s  .  c o  m
                id = i;
            }
        }
        return id;
    }

    /**
     * @param numbers
     * @return
     *       index of the smallest number in the given array
     */
    public static int min(int[] numbers) {
        if (numbers.length == 0)
            return -1;
        int min = numbers[0];
        int id = 0;
        for (int i = 1; i < numbers.length; i++) {
            int n = numbers[i];
            if (n < min) {
                min = n;
                id = i;
            }
        }
        return id;
    }
}

Related

  1. min(double[] array)
  2. min(double[] array)
  3. min(double[] da)
  4. min(double[] data)
  5. min(double[] matrix)
  6. min(double[] series)
  7. min(double[] vals)
  8. min(double[] values)
  9. min(double[] values)