美文网首页
逻辑运算符

逻辑运算符

作者: 南国铃子 | 来源:发表于2019-06-25 13:59 被阅读0次

-----2019/6/25

&,|,&&,||,!

&与&&,效果相同,运算机制不同

-------------------------------------------------------------------------------------------

class Demo2{

public static void main(String[] args){

int math = 88;

int chinese = 23;

//单号不智能,即使前面的结果能够决定最后的结果,但后面的表达式依旧要计算;

System.out.println((math >= 60) | (++chinese >= 60));

System.out.println(chinese);

                              //双||号智能,前面的结果决定最后的结果,后面的表达式无需计算;

System.out.println((math >= 60) || (++chinese >= 60));

System.out.println(chinese);

                                System.out.println((math >= 60) & (++chinese >= 60));

System.out.println(chinese);

//前面的表达式为true,后面为false,后面的表达式还需计算,如下:

                                int chinese1 = 23;

System.out.println((math >= 60) && (++chinese1 >= 60));

System.out.println(chinese1); //24

//前面的表达式能决定最后的结果,后面的表达式无需计算,如下:

                                int math1 = 45;

int chin = 23;

System.out.println((math1 >= 60) && (++chin >= 60));

System.out.println(chin);//23

boolean result = !true;

System.out.println(result);

System.out.println(!((math >= 60) || (++chinese >= 60)));

}

}

相关文章

  • 1.4.运算符

    按功能分为: 算术运算符 赋值运算符 关系运算符 逻辑运算符 位运算符 其他运算符 ---------- 逻辑运算...

  • JavaScript逻辑运算符与赋值运算符

    逻辑运算符 JavaScript中有三个逻辑运算符,&&与、||或、!非。 JavaScript 中的逻辑运算符可...

  • 1.3 Python 运算符

    1.3.1 算数运算符 1.3.2 关系运算符 1.3.3 赋值运算符 1.3.4 逻辑运算符 注: 逻辑运算优先...

  • day05赋值运算符.三元运算符.三元运算符在分页业务逻辑中使用

    赋值运算符 比较运算符 三元运算符 三元运算符在分页业务逻辑中使用 逻辑运算符

  • 逻辑运算符

    赋值运算符 比较运算符 先运算再比较 逻辑运算符 比较大于逻辑!,&&,|| 单目运算符(!++ -- & ) 大...

  • 03-基本运算

    运算符可以分为:算术运算符、比较运算符和逻辑运算符。 优先级是:算术运算符>比较运算符>逻辑运算符。 不过呢,开始...

  • 03-基本运算

    运算符可以分为:算术运算符、比较运算符和逻辑运算符。优先级是:算术运算符>比较运算符>逻辑运算符。不过呢,开始没背...

  • 【Python】运算符

    基本运算符 比较运算符 逻辑运算符

  • 运算符

    算术运算符 + - * / % ++ -- 比较运算符 ><<=>= == 逻辑运算符 & &&| ||^! &...

  • 第三章的语法条件判断

    3.1.7 逻辑运算符 1、逻辑与运算符&& 逻辑与运算符是一个二元运算符,因为它合并两个逻辑表达式,即两个值为t...

网友评论

      本文标题:逻辑运算符

      本文链接:https://www.haomeiwen.com/subject/miptcctx.html