Scanner input error
I want to make a very simple program that allows the user to enter a key/character and have the corresponding unicode value returned. The problem is that I receive an error after the input of any character.
Here is the code:
import java.util.Scanner;
public class KeyMap
{
public static void main (String args[])
{
int number; //the future unicode value.
System.out.print ("Enter the key you want the unicode number of: ");
Scanner scan = new Scanner (System.in);
number = scan.nextInt();
char key = (char)number;
System.out.print ("The number for key " + key + " is " + number);
}
}
And I get this error in the run log after the character is entered:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:819)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at KeyMap.main(KeyMap.java:11)
KeyMap has exited with status 1.
Thanks for any help!

