java中x = x ++的输出 [英] output of x = x++ in java

查看:214
本文介绍了java中x = x ++的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么语句的输出:



int x = 1;

x = x ++;

系统.out.println(x);





是1,但不是2 ???

Why the output of statements:

int x = 1;
x = x++;
System.out.println(x);


is 1, but not 2???

推荐答案

因为这就是你告诉它的事情。 :D $ / $




0)将x的当前值放在安全的地方。

1)增量x。

2)将前一个值存回x。
Because that''s what you told it to do. :D


0) Put the curent value of x in a safe place.
1) Increment x.
2) Store the previous value back into x.


在这种情况下,有后增量...因此x的值将为1 ..

尝试做x = ++ x;然后会显示2 ...



欢呼
In this case, there is post increment...therefore the value of x will be 1..
try to do x=++x; then it will show 2...

cheers


这篇关于java中x = x ++的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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