gpt4 book ai didi

java自增操作不自增

转载 作者:行者123 更新时间:2023-12-01 22:18:28 25 4
gpt4 key购买 nike

public static void main(String[] args) {
int x = 10;
x = x++;
x = x++;
x = x++;
System.out.println(x);
}

为什么预期输出是 13 时输出却是 10?

最佳答案

后递增运算符x++返回x的原始值。因此,x=x++x 的旧值赋回 x

关于java自增操作不自增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478454/

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