Casting
Completed
Read a decimal number. Print it cast to int, then Math.round of it, then the character whose code is that rounded number cast to char.
Input
One decimal number between 65 and 90.
Output
Three lines.
Example
Input
65.7
Output
65 66 B
Editor
Java
Hints
(int) chops off the decimal part.
Math.round rounds to the nearest whole number and returns a long.
Solution explanation
Narrowing conversions (double → int, long → char) need an explicit cast because they can lose information.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x = sc.nextDouble();
int truncated = (int) x;
long rounded = Math.round(x);
System.out.println(truncated);
System.out.println(rounded);
System.out.println((char) rounded);
}
}