【Java基础】三元运算符 a>b ? 1 : 2 ;

1.三元运算符

a > b ? true:false;

可以简化为if-else语句

if(a>b){
	System.out.println("true");
}else{
	System.out.println("false");
}

2.运算符的优先级

只有单目运算符、三元运算符、赋值运算符是从右向左运算的。
image

posted @ 2022-08-19 10:00  植树chen  阅读(142)  评论(0编辑  收藏  举报