max() long in Java

max(): This method is available in the Math class of Java.

Syntax:

long java.lang.Math.max(long a, long b)

This method takes two arguments of type long as its parameters. This method returns the greater of two long values. That is, the result is the argument closer to the value of Long.MAX_VALUE

Note:

If the arguments have the same value, the result is that same value.

Parameters: Two parameters are required for this method.

a: an argument.

b: another argument.

Returns: the larger of a and b.

For Example:

Math.max(1001828, 181881) => It returns 1001828.

Approach

Java

public class MaxLong {
    public static void main(String[] args) {

        long a = 1001828, b = 181881;
        System.out.println(Math.max(a, b));

    }
}

Output:

1001828

No comments:

Post a Comment