gpt4 book ai didi

java - 为什么java int允许使用|运算符(operator) ?其评价如何?

转载 作者:行者123 更新时间:2023-12-02 09:44:01 24 4
gpt4 key购买 nike

我尝试编译并运行以下代码

public static void main(String... args) {
int x = 1 | 2 | 3 | 4;
//int x = 1 | 1 | 1 ;
//int x = 1 | 2 ;
//int x = 2 | 1 ;
System.out.println(x);
}

我在 dot net 中尝试过,但它不工作,为什么它在 java 中工作?如何评估这段代码以产生答案?

最佳答案

1 | 2 = 00000001 | 00000010 = 00000011 = 3
3 | 3 = 00000011 | 00000011 = 00000011 = 3
3 | 4 = 00000011 | 00000100 = 00000111 = 7

关于java - 为什么java int允许使用|运算符(operator) ?其评价如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16562739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com