If --x and x-- are different arguments, then why do they appear to yeild the same output when ran in Code Playground? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

If --x and x-- are different arguments, then why do they appear to yeild the same output when ran in Code Playground?

https://code.sololearn.com/cELUWa8ZixVZ/?ref=app

2nd Jan 2018, 2:29 PM
Charles Street
Charles Street - avatar
5 Respostas
+ 16
try replacing x-- with x=x-- ; & when u write ---x replace it with x=--x ; //U will get the difference /* the difference is not visible another line , when we we assign this value to a different variable or its remain unassigned(just incremented or decremented) */
2nd Jan 2018, 3:30 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
right @Vadim šŸ‘
2nd Jan 2018, 3:38 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
try this: int x = 0; System.out.println(x++); x=0; System.out.println(++x);
2nd Jan 2018, 2:33 PM
Leander
Leander - avatar
+ 2
In this case there is a difference: int x = 3; while(x > 0) { System.out.println(x--); } int y = 3; while(y > 0) { System.out.println(--y); } See also: https://www.sololearn.com/learn/Java/2141/
2nd Jan 2018, 3:35 PM
Š’Š°Š“ŠøŠ¼ Š”ухŠ¾Ń‚ŠøŠ½ (Vadim Sukhotin)
Š’Š°Š“ŠøŠ¼ Š”ухŠ¾Ń‚ŠøŠ½ (Vadim Sukhotin) - avatar
+ 1
maybe this helps you to understand šŸ˜Š
2nd Jan 2018, 2:34 PM
Leander
Leander - avatar