Write a Java program to Perform the ceiling operation on the decimal number using the library method


This Java program reads a double value from the user and then uses the Math.ceil method to round the value up to the nearest integer. Here's a breakdown of the program:

  • The import java.util.*; statement imports the java.util package, which contains the Scanner class that is used to read input from the user.
  • The public class Ceiling_Operation statement declares a public class called Ceiling_Operation, which is the name of the Java file that this program is saved in.
  • The public static void main(String[] args) method is the entry point for the program. It takes an array of strings as an argument, but in this program, that argument is not used.
  • Inside the main method, a new Scanner object called input is created to read input from the user.
  • A double variable num is declared and initialized to 0.
  • The program prompts the user to enter a double value using System.out.print and reads it using input.nextDouble().
  • The Math.ceil(num) method is used to round num up to the nearest integer.
  • The result is then printed to the console using System.out.print.

Source Code

import java.util.*;
public class Ceiling_Operation
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		double num = 0;
 
		System.out.print("Enter the Number : ");
		num = input.nextDouble();
 
		System.out.print("Number After Ceiling Operation : " + Math.ceil(num));
	}
}

Output

Enter the Number : 24
Number After Ceiling Operation : 24.0

Example Programs