max() float in Java

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

Syntax:

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

This method takes two arguments of type float as its argument. This method returns the greater of two float values.

Note:

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

2. If either value is NaN, then the result is NaN.

3. If one argument is positive zero and the other negative zero, the result is positive zero. 

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(17,18) = > It returns 18.0

Approach

Java

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

        float a = 17, b = 18;
        System.out.println(Math.max(a, b));

    }
}

Output:

18.0

No comments:

Post a Comment