Java ceil() method with Examples
The java.lang.Math.ceil() returns the double value that is greater than or equal to the argument and is equal to the nearest mathematical integer.
Note:
- If the argument is Integer, then the result is Integer.
- If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
- If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Syntax:
public static double ceil(double a)
a : the argument whose ceil value is to be determined
Returns : This method returns the double value that is greater than or equal to the argument and is equal to the nearest mathematical integer.
Example 01:To show working of java.lang.Math.ceil() method.
java
import java.lang.Math;
class Gfg {
public static void main(String args[])
{
double a = 4.3 ;
double b = 1.0 / 0 ;
double c = 0.0 ;
double d = - 0.0 ;
double e = - 0.12 ;
System.out.println(Math.ceil(a));
System.out.println(Math.ceil(b));
System.out.println(Math.ceil(c));
System.out.println(Math.ceil(d));
System.out.println(Math.ceil(e));
}
}
|
Output:
5.0
Infinity
0.0
-0.0
-0.0
Example 02: To show the working of ceil() with a positive double value
Java
import java.io.*;
class GFG {
public static void main (String[] args) {
double number = 3.5 ;
double result = Math.ceil(number);
System.out.println(result);
}
}
|
Output :
4.0
Last Updated :
04 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...