案例:求三个整数的最大值
需求:定义三个整数,找出最大值并打印在控制台
分析:
1.用三元运算符获取前两个整数的最大值,并用临时变量保存起来
num1 >num2 ? num1 : num2;
2.用三元运算符,让临时最大值,和第三个整数,进行比较,并记录结果
temp > num3 ? temp : num3;
3.输出结果
class A15{
public static void main(String[] args) {
int a = 100;
int b = 2323;
int c = 23542;
int temp = a > b ? a :b;
int rs = temp > c ? temp : c;
System.out.println(rs);
}
}
