我要用java的方法来写输入三个整数,把这三个整数按从大到小的顺序输出。方法不限
时间: 2024-02-21 12:57:48 浏览: 13
好的,以下是使用Java实现输入三个整数,将它们按从大到小的顺序输出的代码示例:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
scanner.close();
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
if (a > b) {
int temp = a;
a = b;
b = temp;
}
System.out.println(c + " " + b + " " + a);
}
}
```
你可以在控制台输入三个整数,例如 `5 3 9`,程序会将它们按从大到小的顺序输出,即 `9 5 3`。
希望这个示例能够帮助到你!