用JAVA编写程序:由键盘输入三个整数分别存入变量num1、num2、num3,对它们进行序(使用if- else if-else),并且从小到大输出。作业下周三之前交
时间: 2023-04-10 20:03:30 浏览: 140
用JAVA实现3个数排序
4星 · 用户满意度95%
以下是用JAVA编写的程序,可以实现输入三个整数并按照从小到大的顺序输出:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1 = input.nextInt();
int num2 = input.nextInt();
int num3 = input.nextInt();
if (num1 <= num2 && num1 <= num3) {
if (num2 <= num3) {
System.out.println(num1 + " " + num2 + " " + num3);
} else {
System.out.println(num1 + " " + num3 + " " + num2);
}
} else if (num2 <= num1 && num2 <= num3) {
if (num1 <= num3) {
System.out.println(num2 + " " + num1 + " " + num3);
} else {
System.out.println(num2 + " " + num3 + " " + num1);
}
} else {
if (num1 <= num2) {
System.out.println(num3 + " " + num1 + " " + num2);
} else {
System.out.println(num3 + " " + num2 + " " + num1);
}
}
}
}
```
希望能对您有所帮助。
阅读全文