Java based (Basis) ternary operator -----

grammar:

   Type variable name = Expression 1 Expression 2:? Expression 3

The ternary operator is actually a simple if conditional statement in Expression 1 performed to TRUE expression 2  else the expression 3

package com.practice;

public class Practice {
    public static void main(String[] args) {
        int m=2;
        int n=3;
        String str=n>m?"n大于m":"n小于m";
        System.out.println(str);
        
        int a=3;
        int b=7;
        int c=5;
        int max=a>(b>c?b:c)?a:(b>c?b:c);
        System.out.println(b);
    }
}

 

Guess you like

Origin www.cnblogs.com/fengfuwanliu/p/11391988.html