美文网首页
三元运算符

三元运算符

作者: 哈迪斯Java | 来源:发表于2021-09-07 10:25 被阅读0次

    三元运算符的例子,条件?真:假
    package operator;

    //三元运算符
    public class Demon8 {
    public static void main(String[] args) {
    // x ? y:z
    //x为条件,y为真,z为假
    //如果x==true,那么结果为y,否则结果为z

        int score = 10;
        String type = score<60 ?"不及格":"及格";
        System.out.println(type);
    
    
    }
    

    }

    相关文章

      网友评论

          本文标题:三元运算符

          本文链接:https://www.haomeiwen.com/subject/hcqywltx.html