0

Output question

boolean b=true; for(int i=0;i<10;i++) if(b!=b) System.out.print(i);

28th Feb 2021, 2:07 PM
Achintya Raj
Achintya Raj - avatar
9 ответов
+ 4
Àçhîñtyà Ràj Try to do a double check, whether the condition was `if( b != b )` or `if( b = !b ) ` these two are working differently. The latter supposedly give output as you described.
28th Feb 2021, 2:50 PM
Ipang
+ 2
Àçhîñtyà Ràj There is b = !b so after iteration the value of b will change. That's why output is 1 3 5 7 9
28th Feb 2021, 3:07 PM
A͢J
A͢J - avatar
+ 1
Ok thanks
28th Feb 2021, 2:42 PM
Achintya Raj
Achintya Raj - avatar
0
No but it is showing output 13579
28th Feb 2021, 2:24 PM
Achintya Raj
Achintya Raj - avatar
0
Reason I don't know
28th Feb 2021, 2:25 PM
Achintya Raj
Achintya Raj - avatar
0
Yes u are right but this question was asked in a challenge and there was no option available as no output and the correct answer was 13579
28th Feb 2021, 2:32 PM
Achintya Raj
Achintya Raj - avatar
0
Àçhîñtyà Ràj See here after every iteration value of b is changing https://code.sololearn.com/ceE69hdiDc5D/?ref=app
28th Feb 2021, 3:11 PM
A͢J
A͢J - avatar
0
Yes sorry everyone by mistake
28th Feb 2021, 3:17 PM
Achintya Raj
Achintya Raj - avatar
0
It was b=!b
28th Feb 2021, 3:17 PM
Achintya Raj
Achintya Raj - avatar