1、|和||的区别:如果|左边的布尔值为true,则它还会继续判断右边的布尔值;而||则会直接短路,不去判断右边的布尔值。
下面是测试程序:
public class Test
{
public static void main(String[] args)
{
/*
int x = 3,y = 4;
boolean ch;
ch = x < y | ++x == --y;
System.out.println(ch);
System.out.println(x);
System.out.println(y);
*/
int x = 3, y = 4;
boolean ch;
ch = x < y || ++x == --y;
System.out.println(ch);
System.out.println(x);
System.out.println(y);
}
}