下面这段代码的意思的?public class Ceshi {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubint x = 1,y = 1; if(x++==2 & ++y==2) { x =7; } System.out.println("x="+x+",y="+y); }}运行结果是:x=2,y=2int x = 1,y = 1; if(x++==2 && ++y==2) { x =7; } System.out.println("x="+x+",y="+y); 这两个程序 有什么区别?

问题描述:

下面这段代码的意思的?
public class Ceshi {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 1,y = 1;
if(x++==2 & ++y==2) {
x =7;
}
System.out.println("x="+x+",y="+y);
}
}
运行结果是:x=2,y=2
int x = 1,y = 1;
if(x++==2 && ++y==2)
{
x =7;
}
System.out.println("x="+x+",y="+y); 这两个程序 有什么区别?

& 是位运算符 && 是关系运算符 你的两段程序差异就在这里