Java self addition and self subtraction operation process

No more nonsense. I'll post the code directly to you. The specific code is as follows:

output

i 2 j 7 k 7 h 3 p1 0 p2 1 q1 1 q2 0

Analysis: the difference between I + + and + + I is that one is the self increment after the completion of the program and the other is the self increment before the start of the program.

The process of "I = I + + + + + I" is to execute I + + first, but the operation of increasing I by 1 will be executed later, so I is still 0 at this time, and then execute + + I. The value of I after + + I is 1. After + + I is executed, I + + should be added. Therefore, the value of I is actually 2,0 + 2 = 2, and then assigned to I. the final value of I is 2

"J = + + j + j + + + j + + + j + +", the execution process is to first + + J, so the value of J is 1, and then execute j + +. The value of J after j + + is still 1, and then execute j + +. The result after execution is still 1, but the previous j + + needs to be added, so the actual value of J is 2 at this time, and then execute the last j + +. The result after execution is still 2, but the previous j + + needs to be added, So the value of J is actually 3, so 1 + 1 + 2 + 3 = 7, and then assigned to j, and the final value of J is 7

The process of "k = K + + + K + + + K + + + + k" is to execute K + + first, so the value of K is 0, and then execute K + +. After K + +, the value of K is still 0, but the previous K + + needs to be added, so the value of K is actually 1 at this time, and then execute the last K + +, and the result after execution is still 1, but the previous K + + needs to be added, so the value of K is actually 2 at this time, and finally execute + + K, and the result is 3, Add K + +, the actual result of K is 4, so 0 + 1 + 2 + 4 = 7, and then assign it to K, and the final value of K is 7.

"H = + + H + + + H" is to automatically increase h, H value is 1, and then self increase. H value is 2, so 1 + 2 = 3, and then assign it to H. finally, the value of H is 3

"Q1 = + + P1" first increases P1, the value of P1 is 1, and then assigns it to Q1, so the value of Q1 is 1

"Q2 = P2 + +" first assigns P2 to Q2, the value of Q2 is 0, and then increases P2 automatically, so the value of P2 is 1.

The above is the Java self addition and self subtraction operation process introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>