标签:表达式2 ima 关系运算 sys otf 相同 报错 alt 技术
int n = 5;
boolean t = n > 0;//true
boolean f = n < 0;//false
boolean isFive = n == 5;//true
boolean isNotFive = n != 5;//false
System.out.println(t);
System.out.println(f);
System.out.println(isFive);
System.out.println(isNotFive);
boolean and = t && f;//flase
boolean or = t || f;//true
boolean not = !t;//false
System.out.println(or);
System.out.println(and);
System.out.println(not);
表达式1 && 表达式2 :如果表达式1为false,表达式2将不在执行
表达式1 || 表达式2: 如果表达式1为true,表达式2将不在执行
int n = 0;
//boolean b = 5 / n > 0;除数为0,将会报错
boolean and = (n > 5) && (5 / n > 0);
boolean or = (n < 5) || (5 / n > 0);
System.out.println(and);
System.out.println(or);
//利用三元运算符求绝对值
int n = 199;
boolean positive = n >= 0;
int abs = positive ? n : -n;
System.out.println(abs);//199
标签:表达式2 ima 关系运算 sys otf 相同 报错 alt 技术
原文地址:https://www.cnblogs.com/csj2018/p/10246628.html