把任意五个数字按从大到小的顺序排列
我特么写了八十行
话说有没有简单点的方法呀,如果是一百个数那我得写多少行
import java.util.Scanner;public class Main
{ public static void main(String[] args)
{ Scanner s = new Scanner(System.in);
System.out.println("请输入第一个数字:"); int a = s.nextInt();
System.out.println("请输入第二个数字:"); int b = s.nextInt();
System.out.println("请输入第三个数字:"); int c = s.nextInt();
System.out.println("请输入第四个数字:"); int d = s.nextInt();
System.out.println("请输入第五个数字:"); int e = s.nextInt();
int x; if(b > a)
{ x = a;
a = b; b = x;
} if(c > a)
{ x = a;
a = c; c = x;
} if(d > a)
{ x = a;
a = d; d = x;
} if(e > a)
{ x = a;
a = e; e = x;
} if(c > b)
{ x = b;
b = c; c = x;
} if(d > b)
{ x = b;
b = d; d = x;
} if(e > b)
{ x = b;
b = e; e = x;
} if(d > c)
{ x = c;
c = d; d = x;
} if(e > c)
{ x = c;
c = e; e = x;
} if(e > d)
{ x = d;
d = e; e = x;
} System.out.println("这五个数字从大到小排列分别为:");
System.out.println(a+","+b+","+c+","+d+","+e); }
}
我特么写了八十行
话说有没有简单点的方法呀,如果是一百个数那我得写多少行
import java.util.Scanner;public class Main
{ public static void main(String[] args)
{ Scanner s = new Scanner(System.in);
System.out.println("请输入第一个数字:"); int a = s.nextInt();
System.out.println("请输入第二个数字:"); int b = s.nextInt();
System.out.println("请输入第三个数字:"); int c = s.nextInt();
System.out.println("请输入第四个数字:"); int d = s.nextInt();
System.out.println("请输入第五个数字:"); int e = s.nextInt();
int x; if(b > a)
{ x = a;
a = b; b = x;
} if(c > a)
{ x = a;
a = c; c = x;
} if(d > a)
{ x = a;
a = d; d = x;
} if(e > a)
{ x = a;
a = e; e = x;
} if(c > b)
{ x = b;
b = c; c = x;
} if(d > b)
{ x = b;
b = d; d = x;
} if(e > b)
{ x = b;
b = e; e = x;
} if(d > c)
{ x = c;
c = d; d = x;
} if(e > c)
{ x = c;
c = e; e = x;
} if(e > d)
{ x = d;
d = e; e = x;
} System.out.println("这五个数字从大到小排列分别为:");
System.out.println(a+","+b+","+c+","+d+","+e); }
}