本人微信公众号"aeolian"~

倒序输出(指针方法)

题目:输入3个数a,b,c,按大小顺序输出。

        int[] arrays = { 800, 56, 500 };
        for (int i = arrays.length; --i >= 0;) {
            for (int j = 0; j < i; j++) {
                if (arrays[j] > arrays[j + 1]) {
                    int temp = arrays[j];
                    arrays[j] = arrays[j + 1];
                    arrays[j + 1] = temp;
                }
            }
        }
        for (int n = 0; n < arrays.length; n++)
            System.out.println(arrays[n]);

源码

 

点赞

Leave a Reply

Your email address will not be published. Required fields are marked *