代码实现:将一个数组逆序输出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//将一个数组逆序输出。
public class Test {
    public static void main(String[] args) {
        int[] a = {1,2,3,4,5,6,7,8,9};
        for (int i = 0; i < a.length/2; i++) {
            int temp = a[i];
            a[i] = a[a.length-1-i];
            a[a.length-1-i] = temp;
        }
        for (int i : a) {
            System.out.print(i+" ");
        }
    }
 
}

 

posted on   LoaderMan  阅读(825)  评论(0编辑  收藏  举报

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示