Print a letter of the alphabet based on a number that is input
I am trying to print a letter based on the user's input. So far I have:
System.out.println("Enter an integer from 1 to 26:");
Scanner alpha = new Scanner(System.in);
int integer = (char)alpha.nextInt();
char character = (char) integer;
For example, if the number 7 was input, the output would be the letter G.
But all this does is print a blank line, can anyone help me with this?
Re: Print a letter of the alphabet based on a number that is input
To convert the int value 7 to the character 'g' you need to understand the ASCII values. Do a google on the ASCII values and find the int value for the char 'g'.
You can do arithmetic with chars. For example: 'a' + 2 = 'c' or 'g' - 'a' = 6