public class TestIf {
public static void main(String args[]){
int i = 1;
int y = 1;
// if(i = y){Compile Error
//
// }
boolean a = true;
boolean b = true;
if(a = b){
System.out.println("a == b");
}
b = false;
a = false;
if(a = b){
System.out.println("a == b");
} else {
System.out.println("a != b");
}
for(int k = 0; a = b; k++){
if(k < 3)
System.out.println("a == b");
}
for(int k = 0; !(a = b); k++){//bug if there is no break, for loop will not stop, and print a lot of "Tricky a != b", k will become negative value after numerous increment.
if(k < 1)
System.out.println("Tricky a != b");
//break;
}
}
}
Java 逻辑判断boolean赋值
点赞
收藏