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 :To show working of java.lang.Math.ceil() method.
// Java program to demonstrate working // of java.lang.Math.ceil() method import java.lang.Math; class Gfg { // driver code 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)); // Input Infinity, Output Infinity System.out.println(Math.ceil(b)); // Input Positive Zero, Output Positive Zero System.out.println(Math.ceil(c)); // Input Negative Zero, Output Negative Zero System.out.println(Math.ceil(d)); // Input less than zero but greater than -1.0 // Output Negative zero System.out.println(Math.ceil(e)); } } |
Output:
5.0 Infinity 0.0 -0.0 -0.0
Recommended Posts:
- StrictMath ceil() Method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Java Clock tickMinutes() method in Java with Examples
- Java Clock withZone() method in Java with Examples
- Set contains() method in Java with Examples
- Map get() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



