Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recieving 65533 as char value for characters as (à, Ø, æ, æ etc)!

Tags:

java

char

short

I've been trying for hours now to figure out why, when enter a char like Ø in the console through the scanner, to then get the numeric value, I always end up with 65533 (Max value of unsigned short)?

This doesn't seem to be the case for latin characters. Any idea why?

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    char[] chars = sc.next().toCharArray();

    for(int i = 0; i < chars.length; i++){

        System.out.println((int)chars[i]);
    }
}
like image 200
phadam Avatar asked Feb 05 '23 09:02

phadam


1 Answers

65533 = Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)

i.e. Your character is not being interpreted correctly within the character encoding you are using, and so is being replaced by the fallback value.

like image 143
Alohci Avatar answered Mar 05 '23 12:03

Alohci