语法格式:
x ? y : z |
其中 x 为 boolean 类型表达式,先计算 x 的值,若为true,则整个运算的结果为表达式 y 的值,否则整个运算结果为表达式 z 的值。
三目条件运算符
int score=80; String type = score<60?"不及格":"及格"; System.out.println(type); //及格 if(score<60){ System.out.println("不及格"); }else{ System.out.println("及格"); //及格 } int x=-100; System.out.println(x>0?1:(x==0?0:-1)); //-1