Decrement Java | Sololearn: Learn to code for FREE!


Decrement Java

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

2/21/2017 8:28:49 PM

Hermann Set

2 Answers

New Answer


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


Thank you very much. I have always wondered why my answers in challenges werent correct