看板 java 關於我們 聯絡資訊
※ 引述《FAVORITGREEN (壞人嗎>"<)》之銘言: : 比較過前置++y 與後置y++的差異, : 但遇到以下2個比較複雜的情況,算出來答案不一樣, : 能否請教各位高手,說明一下指定及計算的流程? : x=5 , y=10 : 1. z = x-- + ++y = ? 答案是16 --->但我卻算是15 That's because they are increament/ decreament operators with postfix or prefix style. They differ in what to be evaluated. For instance, ++y apply with operator first; so the value becomes 11. But x-- evaluates the original value, i.e. 5. Thus, 5 + 11 = 16. Reference: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op1.html : 2. z = ++x - y-- = ? 答案是-6 --->但我卻算是-3 : 不知道錯誤在哪? : 請各位教我一下!^^ 感恩~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 87.194.42.127