package xiti3;
//求出3个数中的最大值,并输出最大值
public class Third {
public static void main(String[] args) {
/*
* //方法一
int a,b,c,d,max;
a=1;
b=2;
c=3;
if(a>=b){
d=a;
}
else
d=b;
if(d>=c){
max=d;
}else
max=c;
System.out.println("abc中最大值是"+max);
*/
/*
//方法二
int a,b,c,d,max;
a=1;
b=2;
c=3;
d=(a>b)?a:b;
max=(d>c)?d:c;
System.out.println(“abc中最大值是”+max);
*/
//方法三
int a,b,c,max;
a=1;
b=2;
c=3;
max=(((a>b)?a:b)>c)?((a>b)?a:b):c;
System.out.println("abc中最大值是"+max);
}
}
本文通过三种不同的编程方法展示了如何找出三个整数中的最大值,并提供了完整的Java代码实现。第一种方法使用了传统的if-else语句,第二种方法利用了条件运算符简化了代码,第三种方法则进一步优化了条件判断逻辑。
5126

被折叠的 条评论
为什么被折叠?



