Write a program that prompts the user to input an integer
between 0 to 35. It the number is less than or equal to 9, the
program should output the number; otherwise, it should output
A for 10, B for 11, C for 12, …, and Z for 35. (hint: use the cast
operator, (char)(), for numbers >+ 10.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = -1;
while (n < 0 || n > 35) {
System.out.println("Input n. n should be >= 0 and <= 35");
n = scanner.nextInt();
}
if (n >= 0 && n <= 9) {
System.out.println(n);
} else {
System.out.println((char) (55 + n));
}
}
Comments
Leave a comment