printf为同一变量显示不同的值 [英] printf displays different values for the same variable

查看:110
本文介绍了printf为同一变量显示不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到了这个代码,编译时打印5和10:

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);

这怎么可行?!

推荐答案

Java支持Unicode字符,其中一个数字变量中的一个或多个字母是来自不同字母表的unicode字母,您可以通过复制查看 - 粘贴这两个名称并试图这样做:

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"));

它们看起来肉眼相同,但它们不是,你的IDE在控制台中显示为假作为评价结果。自己尝试一下。

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.

编辑:

字母'e'不同,将其输出到int的输出是101和1077,如果你谷歌搜索unicode 1077,以下链接是搜索引擎将向你抛出的众多链接之一:

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

正如你所看到的那样,它是西里尔文小写字母'e'。

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

这篇关于printf为同一变量显示不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆