0
点赞
收藏
分享

微信扫一扫

三元运算符的使用

西特张 2022-04-16 阅读 89
java

格式:条件表达式?表达式1:表达式2;

意为如果条件表达式成立,执行表达式1,如果条件表达式不成立,执行表达式2.

例:已知两个人的体重,输出两人中体重较重的一方的体重

int weight1=55;
int weight2=65;
int max=weight1>weight2?weight1:weiht2
System.out.println(max);
举报

相关推荐

0 条评论