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.
Type casting
Converting and printing double values as integers
Report a typo
Sample Input 1:
7.81Sample Output 1:
7Sample Input 2:
9.6Sample Output 2:
9Write 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
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.