用java代码将数组元素顺序颠倒

package test;

public class Recover {

    public int[] reverse(int[] a) {  
        int[] b = new int[a.length];  
        int n = a.length - 1;
        for (int i = 0; i < a.length; i++) {  
            b[n] = a[i];  
            n--;  
        }  
        return b;  
    }  
  
    public static void main(String[] args) {  
        Recover t = new Recover();  
        int[] a = {1, 2, 3, 4, 5};  
        int[] b = t.reverse(a);  
        for (int i = 0; i < b.length; i++)  
            System.out.print(b[i]+",");  
    }  

}

 

posted on 2017-03-22 14:38  我是齐欢  阅读(1085)  评论(0编辑  收藏  举报