java输入三个整数x,y,z,对齐进行排序,使得x<y<z
时间: 2023-05-28 11:02:42 浏览: 228
以下是示例代码:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入三个整数x,y,z,用空格隔开:");
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
int temp;
if (x > y) {
temp = x;
x = y;
y = temp;
}
if (y > z) {
temp = y;
y = z;
z = temp;
}
if (x > y) {
temp = x;
x = y;
y = temp;
}
System.out.println("排序后的结果为:" + x + " " + y + " " + z);
}
}
```
运行程序后,会提示用户输入三个整数x,y,z,并通过比较大小进行排序,最终输出排序后的结果。
阅读全文