扩展值运算符
package operator;
public class Project6 {
    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);
        //字符串连接符 +
        System.out.println(a+b);
        System.out.println(""+a+b);//""是字符串,“”+后面的运算会把后面的都转换成String类型然后前后合并
        System.out.println(a+b+"A");//""前后位置不同也会决定运算顺序,放前面就会让""里面的内容和后面的运算结果都进行拼接
        //要是放在后面前面就先进行计算再拼接里面的内容
    }
}
条件运算符
package operator;
public class Projetc7 {
    public static void main(String[] args) {
        // X ? Y :  Z
        //如果X==true (X会是一个判断语句)则结果位Y,否则结果为Z
        int score = 50; int score2 = 70;
        String type =score<60?"不及格":"及格";
        String type2 =score2<60?"不及格":"及格";
        System.out.println(type);
        System.out.println(type2);
        //必需掌握
    }
}
                    
                
                
            
        
浙公网安备 33010602011771号