package First;
/*
三元运算符
例题三个和尚
*/
public class ex10 {
public static void main(String [] args ) {
// 1.定义三个变量用于保存和尚的身高
int height1=150;
int height2=210;
int height3=165;
// 2.用三元运算符获取前两个和尚的较高身高值,并用临时身高变量保存起来
int tempHeight = height1>height2?height1:height2;
// 3.用三元运算符获取临时身高和第三个和尚身高较高值,并用最大身高变量保存
int maxHeight=tempHeight>height3?tempHeight:height3;
// 4.输出结果
System .out.println ("maxHeight:"+maxHeight);
}
}
java三个和尚比身高问题
最新推荐文章于 2023-07-03 14:37:39 发布