三元运算符

三元运算符

package operator;
public class demo06 {
    public static void main(String[] args) {
        //三元运算符 x ? a : b
        //如果x=true,则结果为a,否则结果为b

        int x = 50;
        String result = x > 60 ? "及格":"不及格";
        
        System.out.println(result);//结果为不及格
    }
}
posted @ 2023-02-03 16:51  chengh0618  阅读(9)  评论(0编辑  收藏  举报