输入三个整数x,y,z,请把这三个数由小到大输出。
public class Example15 {
public static void main(String[] args) {
sort(15, 10, 5);
}
public static void sort(int x, int y, int z) {
if (x > y) {
int t = x;
x = y;
y = t;
}
if (x > z) {
int t = x;
x = z;
z = t;
}
if (y > z) {
int t = y;
y = z;
z = t;
}
System.out.println("三个数字由小到大排列为: " + x + " " + y + " " + z);
}
}
时间: 2024-10-12 04:05:26