Java经典编程题50道之十五

输入三个整数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);
    }
}

原文地址:https://www.cnblogs.com/qubo520/p/6935409.html