字符串连接和三元运算符

字符串连接符和三元运算符


package operator;

public class Demo07 {
   public static void main(String[] args) {
       int a = 10;
       int b = 20;

       /*
       a+=b;
       a-=b;
        */
       // 字符串连接符 +
       System.out.println(""+a+b);//空字符串在前 后面也当做字符串连接
       System.out.println(a+b+"");//a+b在前 先计算 在和空字符串连接

       System.out.println("===========================");
       //三元运算符
       //x?y:z
       //如果x为真,则结果为y,否则结果为z
       int score = 50;
       String type = score<60?"不及格":"及格";
       System.out.println(type);

  }
}

 

posted @ 2021-05-24 14:00  Dudo1  阅读(71)  评论(0)    收藏  举报