- class ArrayMove
- {
- public static void main(String[] args)
- {
- int[] in={1,2,3,4,5,6,8,9,5,4,6,2};
- printArr(moveArr(in,2));
- }
- public static int[] moveArr(int[] arr,int m){
- //arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
- int n=arr.length;
- int[] result=new int[n];
- System.arraycopy(arr,n-m,result,0,m);
- System.arraycopy(arr,0,result,m,n-m);
- return result;
- }
- public static void printArr(int[] arr){
- System.out.print("[");
- for(int i=0;i<arr.length;i++){
- if(i!=arr.length-1) System.out.print(arr[i]+",");
- else System.out.print(arr[i]+"]");
- }
- System.out.println();
- }
- }
复制代码 |