0

class MyClass { public static void main(String[ ] args) { boolean b = true ; for (int i = 0;i<10;i++) if (b=!b)

expain this plzzz

3rd Aug 2018, 1:19 PM
Ghritika Sharma
Ghritika Sharma - avatar
2 Antworten
0
b=!b changes (flips) the boolean value of b in every iteration. first, b's value was 1. so in first iteration, !b is 0. that makes b=!b equivalent to b=0. same way, in next iteration, b=!b becomes b=1. so in that code, if-condition is met in every odd value of i.
3rd Aug 2018, 1:30 PM
nillyhan
0
thank you
3rd Aug 2018, 1:34 PM
Ghritika Sharma
Ghritika Sharma - avatar