Here is the Java code.
import java.util.Scanner;
import java.io.*;
public class CeilingFloor {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
System.out.println("1-Want demo of Ceiling value of a number..?");
System.out.println("2-Want demo of Floor value of a number..?");
System.out.println();
System.out.print("Select any option: ");
int select = Integer.parseInt(br.readLine());
switch (select) {
case 1:
System.out.println("Here are some examples of Ceiling values: ");
//Returns the same value
System.out.println("Ceiling value of 10 is: " + Math.ceil(10));
//returns a smallest integer which is not less than 10.1, i.e. 11
System.out.println("Ceiling value of 10.1 is: " + Math.ceil(10.1));
//returns a smallest integer which is not less than 5.5, i.e. 6
System.out.println("Ceiling value of 5.5 is: " + Math.ceil(5.5));
//in this case it would be -20
System.out.println("Ceiling value of -20 is: " + Math.ceil(-20));
//it returns -42 not -43. (-42 is grater than 42.4 :) )
System.out.println("Ceiling value of -42.4 is: " + Math.ceil(-42.4));
//returns 0
System.out.println("Ceiling value of 0 is: " + Math.ceil(0));
System.out.println("If you want to test some other numbers then,");
System.out.print("Enter the number: ");
Scanner in = new Scanner(System. in );
float input = in .nextFloat();
System.out.println("Ceiling value of " + input + " is: " + Math.ceil(input));
break;
case 2:
System.out.println("Here are some examples of Floor values: ");
//Returns the same value
System.out.println("floor value of 70 is: " + Math.floor(70));
//returns largest integer which is not less than 30.1, i.e. 30
System.out.println("floor value of 30.1 is: " + Math.floor(30.1));
//returns largest integer which is not less than 15.5, i.e. 15
System.out.println("floor value of 15.5 is: " + Math.floor(15.5));
//in this case it would be -40
System.out.println("floor value of -40 is: " + Math.floor(-40));
//it returns -43.
System.out.println("floor value of -42.4 is: " + Math.floor(-42.4));
//returns 0
System.out.println("floor value of 0 is: " + Math.floor(0));
System.out.println("If you want to test some other numbers then,");
System.out.print("Enter the number: ");
Scanner s = new Scanner(System. in );
float input1 = s.nextFloat();
System.out.println("Ceiling value of " + input1 + " is: " + Math.floor(input1));
break;
}
}
}Thank you, keep learning and sharing.
