对下列代码,若有输出,指出输出结果。
1.
int x = 4;
int y = 1;
if (x > 2){
if (y > 2)
System.out.println(x + y);
System.out.println("qaqaq");
} else
System.out.println("x is" + x);
结果是:qaqaq
class IfExer {
public static void main(String[] args){
int x = 4;
int y = 1;
if (x > 2)
if (y > 2)
System.out.println(x + y);
//System.out.println("qaqaq");
else//就近原则
System.out.println("x is " + x);
}
}
结果是:x is 4
2.
boolean b = true;
if(b == false)
System.out.println("a");
else if(b)
System.out.println("b");
else if(!b)
System.out.println("c");
else
System.out.println("d");
结果是:b
如果写成if(b=false)能编译通过吗?如果能,结果是?
boolean b = true;
if(b = false)
System.out.println("a");
else if(b)
System.out.println("b");
else if(!b)
System.out.println("c");
else
System.out.println("d");
能,结果是:c