In: Computer Science
4.
Prompt user to enter a double number from console. Round this number so it will keep 2 places after the decimal point. Display new number. For example, number 12.3579 will round to 12.36; number 12.4321 will round to 12.43
This is meant to be written in Java 14.0
Source Code:
Output:
Code in text format (See above images of code for indentation):
import java.util.*;
/*class definition*/
public class Main
{
/*main method*/
public static void main(String[] args)
{
/*Scanner object to read data from the user*/
Scanner read=new Scanner(System.in);
double num;
/*read a double number from console*/
System.out.print("Enter a double number: ");
num=read.nextDouble();
/*print upto 2 decimal places*/
System.out.printf("The value rounded to 2 decimal places is: %.2f",num);
}
}