java ternary operator

Ternary operator

  • The format is: X? Y: Z
  • Meaning: If x==Ture, the result output is Y, otherwise the result output is Z
  • Although it can be judged by if flow control, this statement is very commonly used in development, which can make the code more streamlined and easier to understand.
public class Demo05 {
    
    
    public static void main(String[] args) {
    
    

        //X ? Y : Z(如果x==Ture,则结果输出为Y,否则结果输出为Z)
        int score = 90;
        String a = score <= 60 ? "不及格" : "及格";
        System.out.println(a);
    }
}

Guess you like

Origin blog.csdn.net/qq_43409668/article/details/112852303