5-1条件运算符 & 5-2

三目运算符

新建类:

ConditionDemo

用三目运算符:

package com.imooc.operator;

public class ConditionDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a=4,b=7;
        //求和b 的最大值
        int max;//最大值
        if(a>b){
            max=a;
        }else{
            max=b;
        }
        System.out.println("max="+max);
        //三目运算符
        max=a>b?a:b;
        System.out.println("max="+max);
        boolean b1=a>b?(3<6):(true==false);
        System.out.println("b1="+b1);
        
    }

}

5-2 

原文地址:https://www.cnblogs.com/wangjunwei/p/10421343.html