nextDown() float in Java

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

Syntax:

float java.lang.Math.nextDown(float f)

This method takes one argument of type float as its parameter. This method returns the floating-point value adjacent to f in the direction of negative infinity.

Special Cases:

1. If the argument is NaN, the result is NaN.

2. If the argument is negative infinity, the result is negative infinity.

3. If the argument is zero, the result is -Float.MIN_VALUE.

Parameters: One parameter is required for this method.

f: starting floating-point value.

Returns: The adjacent floating-point value closer to negative infinity.

For Example:

Math.nextDown(19.9) = > It returns 19.899998

Approach

Java

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

        float f = (float19.9;
        System.out.println(Math.nextDown(f));

    }
}

Output:

19.899998

No comments:

Post a Comment