public class T36 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
try {
int[] arr = new int[5];
System.out.println("请输入5个数字:");
for (int i = 0; i < arr.length; i++) {
arr[i] = input.nextInt();
}
System.out.println("输入的数组为:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + "\t");
}
System.out.println();
System.out.print("请输入向后移动的位置:");
int m = input.nextInt();
int[] b = new int[arr.length];// 新建一个数组,长度同arr
/* for循环里将往后某位数的多个值取出来,在放到后面的某多个位里去 */
for (int i = arr.length - m - 1; i >= 0; i--) {
b[i + m] = arr[i]; // 根据往后的位数将剩余元素复制到新数组里
}
/* for循环先确定后移位数的元素,并将其从头赋值 */
for (int j = arr.length - m; j < arr.length; j++) {
b[j - (arr.length - m)] = arr[j];// 将移出去的N位数重新赋值到前面
}
/* 结果输出 */
for (int k = 0; k < b.length; k++) {
System.out.print(b[k] + "\t");
}
} catch (Exception e) {
System.out.println("Error!索引超出范围!");
}
}
}