floor() in Java

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

Syntax:

double java.lang.Math.floor(double a)

Thie method tales one parameter as an argument. This method returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. 

Special cases:

1. If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

2.If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Parameters: One parameter is required for this method.

a: A value.

Returns: the largest (closest to positive infinity)floating-point value that is less than or equal to the argument and is equal to a mathematical integer.

For Example:

Math.floor(13.444) = > It returns 13.0

Approach

Java

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

        double a = 13.444;
        System.out.println(Math.floor(a));

    }
}

Output:

13.0

No comments:

Post a Comment