

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java ceil() method with Examples
<p>The java.lang.Math.ceil() 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 −</p><ul class="list"><li><p>If the argument value is already equal to a mathematical integer, then the result is the same as the argument.</p></li><li><p>If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.</p></li><li><p>If the argument value is less than zero but greater than -1.0, then the result is negative zero.</p></li></ul><h2>Example</h2><p>Following is an example to implement the ceil() method in Java −</p><pre class="prettyprint notranslate">import java.lang.*; public class Demo { public static void main(String[] args) { // get two double numbers double x = 125.9; double y = 0.4873; // call ceal for these these numbers System.out.println("Math.ceil(" + x + ")=" + Math.ceil(x)); System.out.println("Math.ceil(" + y + ")=" + Math.ceil(y)); System.out.println("Math.ceil(-0.65)=" + Math.ceil(-0.65)); } }</pre><h2>Output</h2><pre class="result notranslate">Math.ceil(125.9)=126.0 Math.ceil(0.4873)=1.0 Math.ceil(-0.65)=-0.0</pre><h2>Example</h2><p>Let us see another example with negative input values −</p><pre class="prettyprint notranslate">Import java.lang.*; public class Demo { public static void main(String[] args) { // get two double numbers double x = 0.20; double y = -2.4; // call ceal for these these numbers System.out.println("Math.ceil(" + x + ")=" + Math.ceil(x)); System.out.println("Math.ceil(" + y + ")=" + Math.ceil(y)); } }</pre><h2>Output</h2><pre class="result notranslate">Math.ceil(0.2)=1.0 Math.ceil(-2.4)=-2.0</pre>
- Related Questions & Answers
- Java toDegrees() method with Examples
- Java signum() method with Examples
- Java lang.Long.toBinaryString() method with Examples
- Java cbrt() method with Examples
- Java sqrt() method with Examples
- Java floor() method with Examples
- Java streams counting() method with examples
- Java Signature getAlgorithm() method with Examples
- Java Signature getInstance() method with Examples
- Java Signature getProvider() method with Examples
- Java Signature initSign() method with Examples
- Java Signature toString() method with Examples
- Java lang Integer.toHexString() Method with Examples
- Java lang Long.toOctalString() Method with Examples
- Matcher start() method in Java with Examples
Advertisements