Description: The Math.ceil() method is used to return the smallest integer that is greater than or equal to the argument passed to it. In other words, it rounds up the value to the nearest integer that is greater than or equal to the value.
Example 1: Suppose we have a double value, say 8.25, and we want to round it up to the nearest integer. We can use the Math.ceil() method to achieve this by passing the value as an argument to the method as shown below:
double num = 8.25; int result = (int)Math.ceil(num); // result = 9
Example 2: Suppose we have a program that calculates the cost of shipping a package based on its weight. We can use the Math.ceil() method to round up the weight to the nearest integer, which would give us a more accurate calculation. Here's how we can use the method in our program:
double weight = 5.7; // assume weight is in pounds int roundedWeight = (int)Math.ceil(weight); // round up weight to nearest integer double shippingCost = roundedWeight * 2.5; // calculate shipping cost System.out.println("Shipping cost for " + weight + "lbs package is $" + shippingCost);
Package Library: java.util
Java Math.ceil - 30 examples found. These are the top rated real world Java examples of java.util.Math.ceil extracted from open source projects. You can rate examples to help us improve the quality of examples.