Java Number Min Value min(int a, int b)

Here you can find the source of min(int a, int b)

Description

Returns the smaller number of a and b.

License

LGPL

Parameter

Parameter Description
a value.
b value.

Return

min

Declaration

public static int min(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from   w w  w . ja  v a2 s . co  m*/
     * Returns the smaller number of a and b.
     * @param a value.
     * @param b value.
     * @return min
     */
    public static int min(int a, int b) {
        return a < b ? a : b;
    }

    /**
     * Returns the smaller number of a, b and c.
     * @param a value.
     * @param b value.
     * @param c value.
     * @return min
     */
    public static int min(int a, int b, int c) {
        return min(min(a, b), c);
    }

    /**
     * Returns the smallest number contained in the provided array.
     * @param numbers Array of numbers
     * @return min
     */
    public static int min(int... numbers) {
        if (numbers.length < 1) {
            throw new IllegalArgumentException();
        }
        int min = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
            }
        }
        return min;
    }

    /**
     * Returns the smaller number of a and b.
     * @param a value.
     * @param b value.
     * @return min
     */
    public static double min(double a, double b) {
        return a < b ? a : b;
    }

    /**
     * Returns the smaller number of a, b and c.
     * @param a value.
     * @param b value.
     * @param c value.
     * @return min
     */
    public static double min(double a, double b, double c) {
        return min(min(a, b), c);
    }

    /**
     * Returns the smallest number contained in the provided array.
     * @param numbers Array of numbers
     * @return min
     */
    public static double min(double... numbers) {
        if (numbers.length < 1) {
            throw new IllegalArgumentException();
        }
        double min = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
            }
        }
        return min;
    }

    /**
     * Returns the smaller number of a and b.
     * @param a value.
     * @param b value.
     * @return min
     */
    public static float min(float a, float b) {
        return a < b ? a : b;
    }

    /**
     * Returns the smaller number of a, b and c.
     * @param a value.
     * @param b value.
     * @param c value.
     * @return min
     */
    public static float min(float a, float b, float c) {
        return min(min(a, b), c);
    }

    /**
     * Returns the smallest number contained in the provided array.
     * @param numbers Array of numbers
     * @return min
     */
    public static float min(float... numbers) {
        if (numbers.length < 1) {
            throw new IllegalArgumentException();
        }
        float min = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
            }
        }
        return min;
    }
}

Related

  1. min(int a, int b)
  2. min(int a, int b)
  3. min(int a, int b)
  4. min(int a, int b)
  5. min(int a, int b)
  6. min(int a, int b)
  7. min(int a, int b)
  8. min(int a, int b, int c)
  9. min(int a, int b, int c)