Java学习笔记(4.9)判断语句二

if语句与三元运算符的转换

public class Main {
    public static void main(String[] args) {
       int a=100;
       int b=200;
       int max=a>b?a:b;
       System.out.println(max);
    }
}
//三元运算符取最大值可用if语句表示为
public class Main {
    public static void main(String[] args) {
       int a=100;
       int b=200;
       int max;
       if(a>b){
           max=a;
       }
       else
           max=b;
       System.out.println(max);
    }
}
posted @ 2021-04-09 09:01  陈二胖爱吃梨  阅读(20)  评论(0)    收藏  举报