0

What does --X mean (the X part)

4th Mar 2017, 3:07 PM
One Puncher
One Puncher - avatar
5 Respostas
+ 2
--X means reduce X in one unit and then get its value. So, Y=--X is equivalent to X-=X; Y=X;
4th Mar 2017, 3:14 PM
Qwerty
0
So basically it would be like --X would be one if X =2?
5th Mar 2017, 3:16 AM
One Puncher
One Puncher - avatar
0
Yes, but not only that. It would give back the value 1, so if X=2, System.out.println(Integer.toString(--X)); would print "1". On the other hand, if you write X--, first you get back the value of X and then then decrements it by one, so if X=2, System.out.println(X--) would print 2. Integer.toString converts an integer value into a string. It is done automatically if you don't write so.
5th Mar 2017, 6:45 AM
Qwerty