Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

converting a char to uppercase (char cannot be dereferenced)?

807601Apr 16 2008 — edited Apr 16 2008
I have written a program using case to output a country when inputting a character. Just in case people use lower case letters i want to change to uppercase ive tried using toUpperCase but the program keeps giving me the error messahe char cannot be dereferenced.
my code is :
 char idchar;
        
        System.out.println("A Andorra");
        System.out.println("B Belgium");
        System.out.println("F Finland");
        System.out.println("M Malta");
        System.out.println("S Slovenia");
        System.out.println("\nChoose a country from menu above:");
        
        Scanner scanner = new Scanner(System.in);
        idchar = scanner.next().charAt(0);
        
        switch (idchar)
        {
            case 'A':
                System.out.println("You chose \"Andorra\"");
                break;
            case 'B':
                System.out.println("You chose \"Belgium\"");
                break;
            case 'F':
                System.out.println("You chose \"Finland\"");
                break;
            case 'M':
                System.out.println("You chose \"Malta\"");
                break;
            case 'S':
                System.out.println("You chose \"Slovenia\"");
                break;
            default:
                System.out.println("That country is not on the list");
        }
Any suggestions
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2008
Added on Apr 16 2008
7 comments
1,009 views