三个数a b c
int a = 10;
int b = 100;
int c = 1000;
第一种方式if嵌套
int max = 0;
if (a > b) {
if (a > c) {
max = a;
} else {
max = c;
}
} else if (b > a) {
if (b > c) {
max = b;
} else {
max = c;
}
} else if (c > a) {
if (c > b) {
max = c;
} else {
max = b;
}
}
第二种方式三元运算符
int temp = a>b?a:b;
int max = temp>c?temp:c;
System.out.println(max);
原文地址:https://www.cnblogs.com/fengxia/p/10202317.html
时间: 2024-10-01 07:53:14