Java Number Max Value max(int a, int b)

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

Description

Returns the bigger number of a and b.

License

LGPL

Parameter

Parameter Description
a value.
b value.

Return

max

Declaration

public static int max(int a, int b) 

Method Source Code

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

public class Main {
    /**//from   w  ww  .j  a  v a  2s  .  co m
     * Returns the bigger number of a and b.
     * @param a value.
     * @param b value.
     * @return max
     */
    public static int max(int a, int b) {
        return a > b ? a : b;
    }

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

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

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

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

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

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

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

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

Related

  1. max(float a, float b, float c, float d, float e)
  2. max(float dirOffset, float min, float max)
  3. max(float value1, float value2)
  4. max(float value1, float value2)
  5. max(float x0, float x1)
  6. max(int a, int b)
  7. max(int a, int b)
  8. max(int a, int b)
  9. max(int a, int b)