格式:条件表达式?表达式1:表达式2;
意为如果条件表达式成立,执行表达式1,如果条件表达式不成立,执行表达式2.
例:已知两个人的体重,输出两人中体重较重的一方的体重
int weight1=55;
int weight2=65;
int max=weight1>weight2?weight1:weiht2
System.out.println(max);
微信扫一扫
格式:条件表达式?表达式1:表达式2;
意为如果条件表达式成立,执行表达式1,如果条件表达式不成立,执行表达式2.
例:已知两个人的体重,输出两人中体重较重的一方的体重
int weight1=55;
int weight2=65;
int max=weight1>weight2?weight1:weiht2
System.out.println(max);
相关推荐