java中 & ,&&

  • && 短路与判断
public class ImoocStudent {

    public static void main(String[] args) throws Exception{

        if(1 > 2 && 10/0 == 0)// 执行报错,0不能作为分母
        {
            System.out.println("******");
        }

        if(1 > 2 & 10/0 == 0)// 执行不报错,还没运行到&&的第二个条件
        {
            System.out.println("******");
        }

    }

}
  • 同样的 || 短路或判断
posted @ 2023-06-01 11:19  盘思动  阅读(12)  评论(0编辑  收藏  举报