1.关系运算符
返回值类型:Boolean(布尔值)
符号:== != > < >= <=
例1
package ddouble; public class ddouble { public static void main(String[] args){ int a=2; int b=3; boolean f; f=a==b; System.out.println(f); } } |
2.逻辑运算符
符号: & 逻辑与 | 逻辑或 !逻辑非
&& 短路与 || 短路或
例2
package ddouble; public class ddouble { public static boolean atrue (){ System.out.println("返回True"); return true; } public static boolean afalse(){ System.out.println("返回false"); return false; } public static void main(String[] args){ boolean f; f=afalse()&&atrue(); System.out.println(f); } } |
3.三元运算符
变量=条件?正确时返回的参数;错误时返回的参数;
例3
package ddouble; public class ddouble { public static void main(String[] args){ int a,b; a=1; b=a>0?a:-a; System.out.println(b); } } |
4.运算符优先级
用()