Converting and printing double values as integers

Report a typo

Please write a Java program that reads in a number of type double and prints it to the console as an integer. All values are guaranteed to be within the valid range of their data types.

Sample Input 1:

7.81

Sample Output 1:

7

Sample Input 2:

9.6

Sample Output 2:

9
Write a program in Java 17
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Read the number as a double.
// TODO: Write your code here to read a double from the console

// Convert and print the number to an integer.

// TODO: Write your code here to convert the double to an integer and print it out to the console

scanner.close();
}
}

Create a free account to access the full topic