【发布时间】:2015-05-03 23:53:09
【问题描述】:
谁能解释一下下面代码的实现:
int j = 1;
System.out.println(j-- + (++j / j++));
我希望输出为 3,如下所述: 由于 '/' 的优先级高于 '+',所以首先计算它。
op1 = ++j (Since it is pre-increment, the value is 2, and j is 2)
op2 = j++ (Since it is post-increment, 2 is assigned and j is incremented to 3)
所以括号内的“/”运算的结果是 2 / 2 = 1。 然后是'+'操作:
op1 = j-- (Since it is Post-increment, the value is 3, and j is decremented to 2)
op2 = 1 (The result of the '/' was 1)
所以,结果应该是 3 + 1 = 4。 但是当我评估这个表达式时,我得到 2。这是怎么发生的?
【问题讨论】:
标签: java operator-keyword