三元运算符

三元运算符

package operator;

/**
 * @version: java version 1.8
 * @Author: Mr Theroux
 * @description:
 * @date: 2024-08-20 10:24
 */
public class Demo07 {
    public static void main(String[] args) {
        // x ? y : Z
        //如果x为true,则结果返回y,否则z
        int score = 50;
        String type = score > 60? "合格" : "不合格";
        System.out.println(type);
        //==========================
        System.out.println("=======================");
        //字符串连接符 + , String
        int a = 10;
        int b = 20;
        System.out.println(a+b+"");//运算优先级
        System.out.println(""+a+b);
        System.out.println(a+""+b);

    }
}

posted @ 2024-08-20 10:37  银行脱坑人  阅读(14)  评论(0)    收藏  举报