public class Test2 {
private static int j=0;
private static boolean methodB(int k){
j+=k;
return true;
}

public static void methodA(int i){
boolean b;
b=i<10|methodB(4);//|在这代表什么意思
b=i<10||methodB(8);//||在这代表什么意思是
}
public static void main(String[] args) {
methodA(0);
System.out.println(j);
}
}

解决方案 »

  1.   

    b=i<10|methodB(4);//|在这代表什么意思  --代表位操作运算号,不会短路
    b=i<10||methodB(8);//||在这代表什么意思是 --代表 逻辑运算符,运短路这道题的methodB方法只会被调用一次
      

  2.   

    “或”运算。
    a||b
    a|ba,b只要有一个是true,结果就是true
    ||,| 区别在于,前者,只要a是true就直接返回true,不用判断b了。书上都有写。