Day8三元运算符

package operator;

public class Demo07 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        a+=b;//a=a+b
        a-=b;//a=a-b
        System.out.println(a);

        //字符串连接符     在"+"之前的符号若有String类型的,则会把之后的操作数也转换成String类型的然后进行连接
        System.out.println(a+b);
        System.out.println(""+a+b);
        System.out.println(a+b+"");//String的符号在最后,不会影响之前符号的执行
    }
}
package operator;
//三元运算符
public class Demo8 {
    public static void main(String[] args) {
        //x ? y : z
        //如果x=true,则输出y,否则输出z   务必掌握    后续学习中可以用if循环来代替
        int a = 54;
        String c = a<60 ? "不及格" : "及格";
        System.out.println(c);
    }
}
posted @ 2025-08-29 00:50  冰涿  阅读(11)  评论(0)    收藏  举报