Answer to Question #143072 in Java | JSP | JSF for Hamza saeed

Question #143072
Write a program that prompts the user to input a decimal number and
outputs the number rounded to the nearest integer.
1
Expert's answer
2020-11-09T00:09:40-0500
import java.util.Scanner;




public class Rounded{




   public static void main(String []args){

    Scanner in = new Scanner(System.in);

    System.out.print("Input a decimal number: ");

    double decimal = in.nextDouble();

     

    long rounded = Math.round(decimal);

    System.out.println("Rounded to nearest ingeter: " + rounded);

     

    in.close();

   }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS