i++ and ++i in Java
First remember the main points:
1.i++ is the first value and then the operation.
2.++i is the value after the first operation.
Give me a chestnut:
int y,x=3;y= (++X) + (++x); Then y=?
Analysis: First calculation after the value, first calculate ++x, get the result x=4, then calculate the second ++x,x becomes 5, at this time the first X is 4.
So the last x=5,y=9.
Again, int y,x=3;y= (x + +) + (x + +); Then y=?
Analysis: First take the value after the operation, first take the value x=3, then calculate the first x + +, get x=4, then take the second x=4, and then calculate the second x++,x into 5.
So the last x=5,y=7.
Again, int y,x=3;y= (x + +) + (++x); Then y=?
Analysis: The first value after the operation, first take the value x=3, and then calculate the first x + +, get x=4, and then calculate the second x++,x into 5.
So the last x=5,y=8.
Summary: The results are in the jdk1.8 environment to run the results, in the previous Baidu to the answer is wrong, but provided an analysis of ideas, now according to the above thinking analysis is no fault, so the practice of genuine knowledge (O゜▽゜) o☆[bingo!]
Regain the i++ and ++i in Java