# StrictMath ceil() Method in Java with Examples

All methods of java.lang.StrictMath class : Set 1, Set 2

The java.lang.StrictMath.ceil() is an inbuilt method in Java is used to return the smallest double value, greater than or equal to the given double argument and equal to an integer. It gives rise to three special results:

• The result is the same as the argument when the given argument is equal to the integer.
• The result is the same as the argument when the given argument is NaN, infinity, positive zero or negative zero.
• The result is a negative 0 when the given argument is less than 0 and greater than -1.0.

Syntax:

`public static double ceil(double num)`

Parameters: The method accepts one parameter num of double type whose ceiling value is to be returned.

Return Value: The method returns the smallest floating-point value which is closest to negative infinity and is greater than or equal to the given argument and also equal to the integer.

Examples :

```Input: num = 2.7
Output: 3.0

Input: num = -8.7
Output: -8.0
```

Below programs illustrate the java.lang.StrictMath.ceil() method:
Program 1:

 `// Java praogram to illustrate the ` `// java.lang.StrictMath.ceil() ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `num1 = ``8.7``, num2 = ``7.1``, num3 = ``3.5``; ` ` `  `        ``// It returns ceiling value ` `        ``double` `cValue = StrictMath.ceil(num1); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num1+``" = "` `+ cValue); ` ` `  `        ``cValue = StrictMath.ceil(num2); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num2+``" = "` `+ cValue); ` ` `  `        ``cValue = StrictMath.ceil(num3); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num3+``" = "` `+ cValue); ` `    ``} ` `} `

Output:

```The Ceil value of 8.7 = 9.0
The Ceil value of 7.1 = 8.0
The Ceil value of 3.5 = 4.0
```

Program 2:

 `// Java praogram to illustrate the ` `// java.lang.StrictMath.ceil() ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `num1 = -``8.7``, num2 = -``7.1``, num3 = -``3.5``; ` ` `  `        ``// It returns ceiling value ` `        ``double` `cValue = StrictMath.ceil(num1); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num1+``" = "` `+ cValue); ` ` `  `        ``cValue = StrictMath.ceil(num2); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num2+``" = "` `+ cValue); ` ` `  `        ``cValue = StrictMath.ceil(num3); ` `        ``System.out.println(``"The Ceil value of "``+ ` `                             ``num3+``" = "` `+ cValue);  ` `   ``} ` `} `

Output:

```The Ceil value of -8.7 = -8.0
The Ceil value of -7.1 = -7.0
The Ceil value of -3.5 = -3.0
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.