Home » Java programming language

# Java Math Class static double ceil(double d) with example

**Java Math Class double ceil(double d) method**: Here, we are going to learn about the **double ceil(double d) method** of Math Class with its syntax and example.

Submitted by Preeti Jain, on September 01, 2019

## Math Class double ceil(double d)

- This method is available in java.lang package.
- This method is used to return the least or smallest value of the double type value which is greater than or equal to the given parameter.
- This is a static method so it is accessible with the class name too.
- The return type of this method is double that means it returns the smallest value of the given parameter [double type].
- In this method, we pass only one parameter as an argument.
- This method does not throw any exception.

**Syntax:**

public static double ceil(double d){ }

**Parameter(s):**

double d – A double value whose least or smallest value to be found.

**Note:**

- If we pass "NaN", it returns "NaN".
- If we pass zero, it returns the same.
- If we pass an infinity (positive or negative), it returns the infinity with the same sign.
- If we pass an argument whose value is less than 0 but greater than -1.0, it returns -0.0.
- If we pass an argument whose value after the decimal point is greater than 0, it returns the incremented value by 1.

**Return value:**

The return type of this method is double, it returns the least or smallest value of the double type value which is greater than or equal to the given parameter.

### Java program to demonstrate example of ceil(double d) method

// Java program to demonstrate the example of // ceil(double d) method of Math Class class CeilMethod { public static void main(String[] args) { // Here we are declaring few variables double d1 = -0.0; double d2 = 0.0; double d3 = -7.0 / 0.0; double d4 = 7.0 / 0.0; double d5 = -0.6; double d6 = 1000.0; double d7 = 1000.4; // Display previous value of d1,d2,d3,d4,d5 ,d6 and d7 System.out.println("Old value of d1 before implementation is: " + d1); System.out.println("Old value of d2 before implementation is :" + d2); System.out.println("Old value of d3 before implementation is :" + d3); System.out.println("Old value of d4 before implementation is :" + d4); System.out.println("Old value of d5 before implementation is :" + d5); System.out.println("Old value of d6 before implementation is :" + d6); System.out.println("Old value of d7 before implementation is :" + d7); // Here , we will get (-0.0) because we are passing parameter // (-0.6) because passed value is less than 0 but greater than -1.0 System.out.println("New value of d1 after implementation is :" + Math.ceil(d1)); // Here , we will get (0.0) because we are passing parameter (0.0) System.out.println("New value of d2 after implementation is :" + Math.ceil(d2)); // Here , we will get (-Infinity) because we are passing // parameter (-7.0/0.0) System.out.println("New value of d3 after implementation is :" + Math.ceil(d3)); // Here , we will get (Infinity) because we are passing // parameter (7.0/0.0) System.out.println("New value of d4 after implementation is :" + Math.ceil(d4)); // Here , we will get (-0.0) because we are passing // parameter (-0.6) because passed value is less than // 0 but greater than -1.0 System.out.println("New value of d5 after implementation is :" + Math.ceil(d5)); // Here , we will get (1000.0) because we are passing // parameter (1000.0) because passed value after decimal point // is not greater than 0 so the same number is returned System.out.println("New value of d6 after implementation is :" + Math.ceil(d6)); // Here , we will get (1001.0) because we are passing // parameter (1000.4) because passed value after decimal // point is greater than 0 so the number is incremented by 1 is returned System.out.println("New value of d7 after implementation is :" + Math.ceil(d7)); } }

**Output**

E:\Programs>javac CeilMethod.java E:\Programs>java CeilMethod Old value of d1 before implementation is :-0.0 Old value of d2 before implementation is :0.0 Old value of d3 before implementation is :-Infinity Old value of d4 before implementation is :Infinity Old value of d5 before implementation is :-0.6 Old value of d6 before implementation is :1000.0 Old value of d7 before implementation is :1000.4 New value of d1 after implementation is :-0.0 New value of d2 after implementation is :0.0 New value of d3 after implementation is :-Infinity New value of d4 after implementation is :Infinity New value of d5 after implementation is :-0.0 New value of d6 after implementation is :1000.0 New value of d7 after implementation is :1001.0

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.