public class Test{
public static void main(String[] args){
int x=5;
boolean b1=true;
boolean b2=false;
if((x==4)&&!b2)
System.out.print("1");
System.out.print("2");
if(b2=true)&&b1)
System.out.print("3");
}
}what is the result?
A.2
B.3
C.1 2
D. 2 3
E.1 2 3
F.Complilation fails
G.An exception is thrown at runtime
哪位大哥知道请告诉我原因。谢谢
public static void main(String[] args){
int x=5;
boolean b1=true;
boolean b2=false;
if((x==4)&&!b2)
System.out.print("1");
System.out.print("2");
if(b2=true)&&b1)
System.out.print("3");
}
}what is the result?
A.2
B.3
C.1 2
D. 2 3
E.1 2 3
F.Complilation fails
G.An exception is thrown at runtime
哪位大哥知道请告诉我原因。谢谢
int x=5;
boolean b1=true;
boolean b2=false;
if((x==4)&&!b2) //先看x==4,这是一个boolean表达式,显然x不等于4,所以x==4
//结果是false,那么false与true或者false做与运算都是false,所以这个if判断是false的,因此1不会
//输出!
System.out.print("1");
System.out.print("2"); //2肯定输出,因为这句没有包括在if块中
if((b2=true)&&b1)//这里首先吧b2置成true,在和b1做与运算,所以true &&
//true,一次if为真,输出3。
System.out.print("3");