0
can anyone explain this?
public class Program { public static void main(String[] args) { boolean b= true; for(int i=0; i<10; i++) if(b=!b) System.out.print(i); } } output: 13579
2 Answers
+ 7
b = true, !b = false because we declared b as true. we said b = !b. b is now becoming false and because of that it always by pass by 2 (i = 0 then b is false, i = 1 value is changed to true, i = 2 b is false again etc) because in every new intereation they change value.
b must be true to get inside of if
0
thanks