当前位置:网站首页>Day08 ternary operator extension operator character connector symbol priority

Day08 ternary operator extension operator character connector symbol priority

2022-07-05 07:36:00 33 year old Java enthusiast

Ternary operator ( Conditional operator )

x ? y : z ( Because there are three factors , Commonly known as ternary )

If x ==turn , The result is y, Otherwise z

Conditions ?turn Output :false Output ( amount to if sentence )

package operator;

public class demo06Day07 {
    
    public static void main(String[] args) {
    
        int a = 59;
        //boolean b=true;
        String c= a>60?" pass ":" fail, ";  // If a Greater than 60, Then output the first value , Otherwise, output the second value .
        System.out.println(c);
    }
}


Extended assignment operators

  1. +=
  2. -+
  3. *=
  4. /=
package operator;

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

    }
}

String connector

package operator;

public class demo07Day07 {
    
    public static void main(String[] args) {
    
        int a=10;
        int b = 20;
        System.out.println(" The output is :"+a+b);// First recognize the string , Connect according to string rules 
        System.out.println(" The output is :"+(a+b));// Recognize parentheses , The parentheses are finished , Then connect in sequence 
        System.out.println(a+b+" The output is :");// After the operation, it is connected with the string 
        /*  If the string is recognized first in order , Just connect by string without operation  */
    }
}

Symbol priority , Be careful

  1. If you identify the string first , Is to string all the strings
  2. If the operation is recognized first , Just calculate first and then string .

summary : It depends on which priority , I'll do that .

priority :

  1. () Parentheses operate first
  2. /
  3. According to the order
原网站

版权声明
本文为[33 year old Java enthusiast]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140553220376.html