用java写一个判断三个数最大值
可以使用三元运算符来实现:
public class MaxOfThree {
public static void main(String[] args) {
int a = 10, b = 20, c = 15;
int max = a > b ? (a > c ? a : c) : (b > c ? b : c);
System.out.println("The max number is " + max);
}
}
输出结果为:
The max number is 20
原文地址: https://www.cveoy.top/t/topic/EfH 著作权归作者所有。请勿转载和采集!