加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么两个变量具有相同的名称?

发布时间:2020-12-14 19:21:53 所属栏目:Java 来源:网络整理
导读:参见英文答案 printf displays different values for the same variable????????????????????????????????????1个 ????????????Can (a==1 a==2 a==3) evaluate to true in Java?????????????????????????????????????8个 我执行以下代码,我没有错误,在输出中

参见英文答案 > printf displays different values for the same variable????????????????????????????????????1个
>????????????Can (a==1 && a==2 && a==3) evaluate to true in Java?????????????????????????????????????8个
我执行以下代码,我没有错误,在输出中我看到成功!信息.你能解释一下这种奇怪的行为吗?

public class Main {

    public static void main(String[] args) {
        int р = 0;
        int p = 1;
        if(р == 0 && p == 1) {
            System.out.println("Success!");
        }

    }

You can check the online demo

最佳答案
两者都是不同的变量(但看起来相似),你可以看到UTF-16是不同的

    int р = 0;
    int p = 1;
    if (р == 0 && p == 1) {
        System.out.println("Success!");
        System.out.println("p UTF-16 is " + (int) 'p');
        System.out.println("р UTF-16 is " + (int) 'р');
    }

产量

Success!
p UTF-16 is 112
р UTF-16 is 1088

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读