三元运算符及字符串拼接符

三元运算符(x ? y : z)

public class Demo02 {
    public static void main(String[] args) {
        // x ? y : z
        //如果x==true,则结果为y,否则为z

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

}

字符串拼接符“+”

public class Demo01 {
    public static void main(String[] args) {

        //字符串连接符 +
        System.out.println(a+b);//30
        System.out.println(""+a+b);//1020 String类型在运算之前字符串会进行拼接
        System.out.println(a+b+"");//30 String在后面则不会
    }
}
posted @ 2020-11-18 14:39  IAimHigher  阅读(782)  评论(0)    收藏  举报