1008 数组元素循环右移问题 (20 分)
题目要求: 代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
scan.nextLine();
int [] arr = new int[n];
if (n == m){
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
}
int k = m % n;
for (int i = k; i < n; i++) {
arr[i] = scan.nextInt();
}
for (int i = 0; i < k; i++) {
arr[i] = scan.nextInt();
}
for (int i = 0; i < n; i++) {
if (i == n-1){
System.out.print(arr[i]);
} else{
System.out.print(arr[i] + " ");
}
}
}
}
结果:
|