package test;
import java.util.Scanner;
public class test {
public static void main(String[] args){
//以下是输入整个数组
int n;
int array[];
System.out.println("请输入整数的个数");
Scanner keyboard=new Scanner(System.in);
n=keyboard.nextInt();
array = new int[n];
for (int i = 0; i < n; i++) {
System.out.print("输入第" + (i + 1) + "个数据");
array[i] = keyboard.nextInt();
}
System.out.print("你输入的数组为:");
for(int i=0;i<n;i++) {
System.out.print(array[i] + " ");
}
System.out.print("\n请输入向后移动的位数:");
int m = keyboard.nextInt();
int[] b = new int[m];
for(int i=0; i<m; i++) {
b[i] = array[n-m+i];
}
for(int i=n-1; i>=m; i--) {
array[i] = array[i-m];
}
for(int i=0; i<m; i++) {
array[i] = b[i];
}
System.out.print("位移后的数组是:");
for(int i=0; i<n; i++) {
System.out.print(array[i] + " ");
}
}
}
import java.util.Scanner;
public class test {
public static void main(String[] args){
//以下是输入整个数组
int n;
int array[];
System.out.println("请输入整数的个数");
Scanner keyboard=new Scanner(System.in);
n=keyboard.nextInt();
array = new int[n];
for (int i = 0; i < n; i++) {
System.out.print("输入第" + (i + 1) + "个数据");
array[i] = keyboard.nextInt();
}
System.out.print("你输入的数组为:");
for(int i=0;i<n;i++) {
System.out.print(array[i] + " ");
}
System.out.print("\n请输入向后移动的位数:");
int m = keyboard.nextInt();
int[] b = new int[m];
for(int i=0; i<m; i++) {
b[i] = array[n-m+i];
}
for(int i=n-1; i>=m; i--) {
array[i] = array[i-m];
}
for(int i=0; i<m; i++) {
array[i] = b[i];
}
System.out.print("位移后的数组是:");
for(int i=0; i<n; i++) {
System.out.print(array[i] + " ");
}
}
}