ceil() in Java

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

Syntax:

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

This method takes one argument of type double. This method returns the smallest (closest to negative infinity) double value that is greater 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.

3. If the argument value is less than zero but greater than -1.0, then the result is negative zero. Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x).

Parameters: One parameter is required for this method.

a: A value.

This method returns the smallest (closest to negative infinity)floating-point value that is greater than or equal to the argument and is equal to a mathematical integer.

Approach

Java


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

        double x = 12.56;

        System.out.println(Math.ceil(x));

    }
}

Output:

13.0

No comments:

Post a Comment