JAVA——三个数排序
程序员文章站
2022-05-28 13:10:04
...
package jaz;
import java.util.Scanner;
public class sort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入num1");
int num1 = sc.nextInt();
System.out.println("输入num2");
int num2 = sc.nextInt();
System.out.println("输入num3");
int num3 = sc.nextInt();
int t = 0;
if(num1 > num2){
t = num1;
num1 = num2;
num2 = t;
}
if(num1 > num3){
t = num1;
num1 = num3;
num3 = t;
}
if(num2 > num3){
t = num2;
num2 = num3;
num3 = t;
}
System.out.println("排序");
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);
}
}
运行结果:
输入num1
999
输入num2
99
输入num3
9
排序
9
99
999