Java program to perform the ceiling operation on the decimal number using the library method

Given a decimal number, we have to perform the ceiling operation.
Submitted by Nidhi, on May 16, 2022

Problem Solution:

In this program, we will read a floating-point number from the user using the Scanner class and perform the ceiling operation on the decimal number using the Math.ceil() method.

Program/Source Code:

The source code to perform the ceiling operation on the decimal number using the library method is given below. The given program is compiled and executed successfully.

// Java program to perform the ceiling operation on the 
// decimal number using the library method

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(System.in);

    double num = 0;

    System.out.print("Enter number: ");
    num = X.nextDouble();

    System.out.print("Number after ceiling operation: " + Math.ceil(num));
  }
}

Output:

Enter number: 35.6
Number after ceiling operation: 36.0

Explanation:

In the above program, we imported the "java.util.*" package to use the Scanner class. Here, we created a public class Main that contains a main() method.

The main() method is the entry point for the program. Here, we created a variable num of double type and read its value from the user using the nextDouble() method of the Scanner class. Then we performed the ceiling operation on the given number using the Math.ceil() method and printed the result.

Java Math Class Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.