三个数从小到大排序
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
0
-
描述
-
现在要写一个程序,实现给三个数排序的功能
-
输入
- 输入三个正整数 输出
- 给输入的三个正整数排序 样例输入
-
20 7 33
样例输出
-
7 20 33
代码
总共就三数,还排个啥序啊,直接暴力枚举,简单粗暴省时间
import java.util.Scanner;
public class Test41 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a<=b&&b<=c)
System.out.print(a+" "+b+" "+c+"\n");
else if (a<=c&&c<=b)
System.out.print(a+" "+c+" "+b+"\n");
else if (b<=a&&a<=c)
System.out.print(b+" "+a+" "+c+"\n");
else if (b<=c&&c<=a)
System.out.print(b+" "+c+" "+a+"\n");
else if (c<=a&&a<=b)
System.out.print(c+" "+a+" "+b+"\n");
else
System.out.print(c+" "+b+" "+a+"\n");
sc.close();
}
}