// 题目: 使用三元运算符和标准的if-else 语句分别实现: 取两个数字当中的最大值
public class Demo06Max{
public static void main(String[] args){
int a = 105;
int b =20;
//首先使用三元运算符
//int max= a>b ? a:b;
int max;
if(a>b){
max=a;
}else{
max=b;
}
System.out.println("最大值:"+max);
}
}
三元运算符可与if-else 等效替换
最新推荐文章于 2022-08-06 10:54:10 发布