0
Can anyone explain to me. What is happening in this code?
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); } } } }
17 Respostas
+ 1
"What is the difference between != and =! in Java? - Stack Overflow" https://stackoverflow.com/questions/8825840/what-is-the-difference-between-and-in-java
//Go through this also
+ 2
Sorry Atul I think so I provided you the reverse one 0=false and 1=true. Sorry everyone for it. I was utterly confused
+ 2
Atul helped Atul and won!
+ 1
why 3? where did you see this in the program? have you checked the launch? the program outputs all odd numbers.
+ 1
i'm blind
+ 1
"Why boolean in Java takes only true or false? Why not 1 or 0 also? - Stack Overflow" https://stackoverflow.com/questions/2015071/why-boolean-in-java-takes-only-true-or-false-why-not-1-or-0-also
+ 1
+ 1
Ярослав Вернигора(Yaroslav Vernigora) ya what a coincidence
0
for(variable; condition; addition) <-- for starts a loop
it checks if the variable(i) is <= 3 (i (<) less than or (=) equal to 3)
while the variable(i) is less than 3
it adds +1 to the variable i (i++)
i dont know if this is the answer you wanted but i'm not good at explaining
0
🤭 It looks like you need to come up with another explanation
0
why is bulin 1 a lie? where can I read about it? and yes, which one of you is the real Atul? 😁
0
I understand the logic as follows: since the if expression is executed only when the condition is true, and the string b =!b at each iteration of the loop changes the truth to untruth and vice versa, then in the end it turns out that i is printed every other time. brilliant!
0
Yes Ярослав Вернигора(Yaroslav Vernigora) inshort it skips one iteration, which looks like odd. I get to know about this =! After looking this code 😅
0
Haloo
0
Don't spam here عبدالعزيز عصام
0
Ah! Error... use relational operator... instead of assignment in if statement