输入三个整数x,y,z,请把这三个数由小到大输出
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数");
int num1 = Integer.parseInt(sc.nextLine());
System.out.println("请输入第二个整数");
int num2 = Integer.parseInt(sc.nextLine());
System.out.println("请输入第三个整数");
int num3 = Integer.parseInt(sc.nextLine());
if(num1 < num2) {
int a = num2;
num2 = num1;
num1 = a;
}
if(num2 < num3) {
int a = num2;
num2 = num3;
num3 = a;
}
if(num3 < num1) {
int a = num1;
num1 = num3;
num3 = a;
}
System.out.println("排序后的顺序是:" + num1 + num2 + num3); |