Write a program that reads a floating point value (double) and prints the closest whole number less than and greater than that value. For example , if the number is 28.466, the program would print 28 and 29

Respuesta :

Answer:

  1. public class Main {
  2.    public static void main(String[] args)
  3.    {
  4.        Scanner input = new Scanner(System.in);
  5.        System.out.print("Enter a floating point value: ");
  6.        double value = input.nextDouble();
  7.        System.out.println(Math.floor(value));
  8.        System.out.println(Math.ceil(value));
  9.    }
  10. }

Explanation:

Firstly create a Scanner object (Line 4).

Next, prompt the user to enter a floating point value and assign it to variable value (Line 6 -7).

Use the Java Math floor and ceil method to get the number less than and greater then the value, respectively, and print them out to the console (Line 9 - 10).