java基础编程60题之36

package com.xijiaopractice;

public class Test36 {
	/*
	 * 有n个整数,使其前面各数顺序向后移 m个位置,最后 m个数变成最前面的 m个数
	 */
	public static void main(String[] args) {
		int m=3;
		int n=8;
		int[] a=new int[]{1,2,4,7,8,9,10,16};
		int[] b=new int[a.length];
		for (int i : a) {
			System.out.print(i+"  ");
		}
		for (int i = a.length-m; i < a.length; i++) {
			b[i]=a[i];
		}
		for (int i = a.length-1-m; i>=0; i--) {
			a[i+m]=a[i];
		}
		for (int i = a.length-m; i < a.length; i++) {
			a[i-a.length+m]=b[i];
		}
		System.out.println();
		for (int i : a) {
			System.out.print(i+"  ");
		}
	}
	
}

 

你可能感兴趣的:(java)