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


三元运算符(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在后面则不会
    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM