0

Decrement Java

Is there a difference between x-- and --x ?

21st Feb 2017, 8:28 PM
Hermann Set
Hermann Set - avatar
2 Réponses
+ 6
Yes. --x decrements first and then handles the statement including it. x-- handles the statement first and then decrements x, e.g.: int x =1; System.out.println (--x); // prints 0 // value of x is 0 here int y=1; System.out.println (y--); // prints 1 // value of y is 0 here
21st Feb 2017, 8:47 PM
Tashi N
Tashi N - avatar
+ 1
Thank you very much. I have always wondered why my answers in challenges werent correct
21st Feb 2017, 8:49 PM
Hermann Set
Hermann Set - avatar