Java Array Min Value min(int[] array)

Here you can find the source of min(int[] array)

Description

min

License

Open Source License

Declaration

public static int min(int[] array) 

Method Source Code

//package com.java2s;

public class Main {

    public static int min(int[] array) {
        // Validates input
        if (array == null) {
            throw new IllegalArgumentException("The Array must not be null");
        } else if (array.length == 0) {
            throw new IllegalArgumentException("Array cannot be empty.");
        }/*from  w w  w  . j av a 2  s. c o  m*/
        int iMin = array[0];
        for (int j = 1; j < array.length; j++) {
            if (array[j] < iMin) {
                iMin = array[j];
            }
        }
        return iMin;
    }

    public static short min(short[] array) {
        if (array == null) {
            throw new IllegalArgumentException("The Array must not be null");
        } else if (array.length == 0) {
            throw new IllegalArgumentException("Array cannot be empty.");
        }
        short sMin = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] < sMin) {
                sMin = array[i];
            }
        }

        return sMin;
    }

    public static double min(double[] array) {
        // Validates input
        if (array == null) {
            throw new IllegalArgumentException("The Array must not be null");
        } else if (array.length == 0) {
            throw new IllegalArgumentException("Array cannot be empty.");
        }
        double dMin = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] < dMin) {
                dMin = array[i];
            }
        }
        return dMin;
    }

    public static float min(float[] array) {
        if (array == null) {
            throw new IllegalArgumentException("The Array must not be null");
        } else if (array.length == 0) {
            throw new IllegalArgumentException("Array cannot be empty.");
        }
        float fMin = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] < fMin) {
                fMin = array[i];
            }
        }

        return fMin;
    }

    public static long min(long a, long b, long c) {
        long lX = a;
        if (b < lX) {
            lX = b;
        }
        if (c < lX) {
            lX = c;
        }
        return lX;
    }

    public static int min(int a, int b, int c) {
        int lX = a;
        if (b < lX) {
            lX = b;
        }
        if (c < lX) {
            lX = c;
        }
        return lX;
    }

    public static short min(short a, short b, short c) {
        short sX = a;
        if (b < sX) {
            sX = b;
        }
        if (c < sX) {
            sX = c;
        }
        return sX;
    }

    public static byte min(byte a, byte b, byte c) {
        byte byteX = a;
        if (b < byteX) {
            byteX = b;
        }
        if (c < byteX) {
            byteX = c;
        }
        return byteX;
    }

    public static double min(double a, double b, double c) {
        return Math.min(Math.min(a, b), c);
    }

    public static float min(float a, float b, float c) {
        return Math.min(Math.min(a, b), c);
    }
}

Related

  1. min(int[] arr, int count)
  2. min(int[] array)
  3. min(int[] array)
  4. min(int[] array)
  5. min(int[] array)
  6. min(int[] elements)
  7. min(int[] in, int x1, int x2)
  8. min(int[] list)
  9. min(int[] values)