用JAVA编写●编写程序:由键盘输入三个整数分别存入变量num1、num2、num3,对它们进行序(使用if- else if-else),并且从小到大输出。
时间: 2023-04-10 14:04:33 浏览: 58
好的,以下是用JAVA编写的程序:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1, num2, num3;
System.out.print("请输入三个整数,以空格分隔:");
num1 = input.nextInt();
num2 = input.nextInt();
num3 = input.nextInt();
if (num1 <= num2) {
if (num2 <= num3) {
System.out.println(num1 + " " + num2 + " " + num3);
} else if (num1 <= num3) {
System.out.println(num1 + " " + num3 + " " + num2);
} else {
System.out.println(num3 + " " + num1 + " " + num2);
}
} else {
if (num1 <= num3) {
System.out.println(num2 + " " + num1 + " " + num3);
} else if (num2 <= num3) {
System.out.println(num2 + " " + num3 + " " + num1);
} else {
System.out.println(num3 + " " + num2 + " " + num1);
}
}
}
}
希望能够帮到你!
阅读全文