描述
现在要写一个程序,实现给三个数排序的功能
输入
输入三个正整数
输出
给输入的三个正整数排序
样例输入
20 7 33
样例输出
7 20 33
Java实现
import java.util.Scanner;
/**
* @author InJavaWeTrust
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int temp;
if(a > b){
temp = a;
a = b;
b = temp;
}
if(a > c){
temp = a;
a = c;
c = temp;
}
if(b > c){
temp = b;
b = c;
c = temp;
}
System.out.println(a + " " + b + " " + c);
}
}
本文介绍了一个简单的Java程序,用于接收三个正整数输入,并按从小到大的顺序进行排序。通过使用临时变量交换数值,该程序能够有效地实现三数排序。

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



