printf displays different values for the same variable

user9048633 :

I found this code online and when compiled it prints 5 and 10:

int numbеr = 5;
int number = 10;
System.out.printf("Number one is %d and number two is %d.", numbеr, number);

How can this work ?!

GetMeARemoteJob :

Java supports Unicode characters, one or more of the letters in one of the "numbers" variable is unicode letter from different alphabet, you can check this by copy-pasting both of those names and trying to do this:

System.out.println("numbеr".equals("number"));

They seem same to the naked eye, but they are not, your IDE will show false in the console as the evaluation result. Try it yourself.

EDIT:

The letter 'e' is different, outputs of casting it to int are 101 and 1077, if you do google search for "unicode 1077" the following link is one of the many the search engine will throw at you:

http://www.codetable.net/decimal/1077

As you can see it says it's Cyrillic lowercase letter 'e'.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=432839&siteId=1