用Java程序比较3个数的大小,用if。。。else结构
3个回答
展开全部
public class Du {
public static void main(String[] args) {
int a = 31;
int b = 24;
int c = 125;
int min , middle, max;
if(a > b){
if(a > c){
max = a;
if(b > c){ //a >b && a > c && b > c
middle = b;
min = c;
}else{//a > b < c
min = b;
middle = c;
}
}else{
//c>a>b
max = c;
middle = a;
min = b;
}
}else{ //a < b
if(b < c){
max = c;
min = a;
middle = b;
}else{//a < b > c
if(a < c){
min = a;
middle = c;
max = b;
}else{ //a < b < c
min = a;
middle = b;
max = c;
}
}
}
System.out.println("Min " + min);
System.out.println("Middle " + middle);
System.out.println("Max " + max);
}
}
-------------testing
Min 24
Middle 31
Max 125
public static void main(String[] args) {
int a = 31;
int b = 24;
int c = 125;
int min , middle, max;
if(a > b){
if(a > c){
max = a;
if(b > c){ //a >b && a > c && b > c
middle = b;
min = c;
}else{//a > b < c
min = b;
middle = c;
}
}else{
//c>a>b
max = c;
middle = a;
min = b;
}
}else{ //a < b
if(b < c){
max = c;
min = a;
middle = b;
}else{//a < b > c
if(a < c){
min = a;
middle = c;
max = b;
}else{ //a < b < c
min = a;
middle = b;
max = c;
}
}
}
System.out.println("Min " + min);
System.out.println("Middle " + middle);
System.out.println("Max " + max);
}
}
-------------testing
Min 24
Middle 31
Max 125
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(a>b){
if(b>c){
return "a>b>c";
}
if(b<c)
{
if(a>c){return "a>c>b"}
else{return c>a>b}
}
}
...a<b...........自己判断
if(b>c){
return "a>b>c";
}
if(b<c)
{
if(a>c){return "a>c>b"}
else{return c>a>b}
}
}
...a<b...........自己判断
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int a=0;
int b=0;
int c=0;
`````
public String Sort(int a,int b, int c){
if(a>b>c){
return "a>b>c";
}else if(a>c>b){
return "a>c>b";
}else if(b>a>c){
return "b>a>c";
}else if(b>c>a){
.......类推··
}
}
int b=0;
int c=0;
`````
public String Sort(int a,int b, int c){
if(a>b>c){
return "a>b>c";
}else if(a>c>b){
return "a>c>b";
}else if(b>a>c){
return "b>a>c";
}else if(b>c>a){
.......类推··
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询