编写一个Java小应用程序,用三目条件运算符求程序中给定的4个double数的最大值和最小值,并输出结果。
2个回答
展开全部
public class A
{
public static void main(String[] args)
{
double a=4.6;
double b=7.9;
double c=12.0;
double d=20.5;
double temp1=(a>b)?a:b;
double temp2=(c>d)?c:d;
double max=(temp1>temp2)?temp1:temp2;
System.out.println("最大值铅手是:"槐念嫌高神+max);
double temp4=(a<b)?a:b;
double temp5=(c<d)?c:d;
double min=(temp4<temp5)?temp4:temp5;
System.out.println("最小值是:"+min);
}
}
{
public static void main(String[] args)
{
double a=4.6;
double b=7.9;
double c=12.0;
double d=20.5;
double temp1=(a>b)?a:b;
double temp2=(c>d)?c:d;
double max=(temp1>temp2)?temp1:temp2;
System.out.println("最大值铅手是:"槐念嫌高神+max);
double temp4=(a<b)?a:b;
double temp5=(c<d)?c:d;
double min=(temp4<temp5)?temp4:temp5;
System.out.println("最小值是:"+min);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void mmm(double a,double b,double c,double d){
double max = a>b?a:b;
max = max>樱颂c?max:c;
max = max>d?max:d;
double min = a<b?a:b;
min = min<c?min:c;
min = min<d?min:d;
System.out.println("max:"圆态+max);
System.out.println("min:"橘颂源+min);
}
double max = a>b?a:b;
max = max>樱颂c?max:c;
max = max>d?max:d;
double min = a<b?a:b;
min = min<c?min:c;
min = min<d?min:d;
System.out.println("max:"圆态+max);
System.out.println("min:"橘颂源+min);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询