0

Why the output is 0 not 1?

int x; for(x=20;x>0;x--){} System.out.print(x);

31st Oct 2019, 3:41 PM
Sanzid Sadman
Sanzid Sadman - avatar
4 Réponses
+ 5
When x becomes 1, it still matches the condition that it is greater than 0. So after that x-- is performed on x which then makes it's value 0 while printing.
31st Oct 2019, 4:02 PM
Avinesh
Avinesh - avatar
+ 4
Because x appears to be 0, when the loop condition appears to be false and the loop breaks.
31st Oct 2019, 3:45 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS ,sorry, i made a mistake, you're right)
1st Nov 2019, 9:41 AM
Ярослав Гавриленко
Ярослав Гавриленко - avatar
1st Nov 2019, 9:29 AM
Seb TheS
Seb TheS - avatar