import java.util.Arrays;
class Exercise06
{
 public static void main(String[] args)
 {
  int[] oldArr={0,1,2,3,4,5,6,7,8,9};
  swap(oldArr);  
 }
 void swap(int[] a)
 {
  int[] newa=new int[a.length];//new一个新数组。
  for (int i=a.length-1;i>=0 ;i-- )
  {
   System.arraycopy(a,i,newa, a.length-i, a.length-1);//将源数组从最后元素开始,一次复制给新数组。
  }
  System.out.print(Arrays.toString(newa));//输出数组。
 }
}

解决方案 »

  1.   

    void swap(int[] a) {
    int[] newa = new int[a.length];
    int j = 0;
    for (int i=a.length-1;i>=0 ;i-- ){
     newa[j++] = a[i];
     }
    System.out.print(Arrays.toString(newa));
    }楼主查下api,看下System.arraycopy这个方法是怎么用的
      

  2.   

    楼主你好好看看arraycopy方法,自会明白,看看API文档
      

  3.   

    嗯嗯,谢谢咯,我今天刚刚开始看的API,好像我是自作聪明把它用成可以变的量哦,嗯嗯,谢谢哦
      

  4.   

    public static void main(String[] args) {
    int[] oldArr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    swap(oldArr);
    } static void swap(int[] a) {
    int[] newa = new int[a.length];// new一个新数组。
    for (int i = a.length - 1; i >= 0; i--) {
    System.arraycopy(a, i, newa, a.length - i - 1,  1);// 将源数组从最后元素开始,一次复制给新数组。
    }
    System.out.print(Arrays.toString(newa));// 输出数组。
    }
      

  5.   

    你是对arraycopy这个方法的参数还不太清楚arraycopy(要copy的数组,copy这个数组的起始位置,新的数组,copy到这个新数组的什么位置,copy几个元素到新数组里)
      

  6.   

    public class Arrays {
        public static <T> T[] swap(T[] t, int len) {
    if (t == null || len <= 0)
        return null;
    T temp = null;
    for (int i = 0, j = len - 1; i <= j; i++, j--) {
        temp = t[i];
        t[i] = t[j];
        t[j] = temp;
    }
    return t;
        }    public static void main(String[] args) {
    String[] a = new String[] { "a", "b", "c", "d" };
    swap(a, a.length);
    for (String s : a) {
        System.out.println(s);
    }
        }
    }
      

  7.   

    给你来个精典的:
                  Integer[] oldArr={0,1,2,3,4,5,6,7,8,9};
          List list=Arrays.asList(oldArr);
          Collections.reverse(list);
          System.out.println(list);
      

  8.   

    多看看Arrays里的东西,那里有很多方法