1008 数组元素循环右移问题 (20分) JAVA

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();
		M = M % N;//难点,要考虑M>N的情况
		int[] num = new int[N];
		for(int i = 0; i < num.length; i++) {
			num[i] = scan.nextInt();
		}
		scan.close();
		for(int i = N-M; i < num.length;i++) {
			System.out.print(num[i] + " ");
		}
		for(int i = 0; i < N-M; i++) {
			if(i == N-M-1) {
				System.out.println(num[i]);
				continue;
			}
			System.out.print(num[i] + " ");
		}
		
    }
}
发布了11 篇原创文章 · 获赞 0 · 访问量 175

猜你喜欢

转载自blog.csdn.net/Bryce_Loski/article/details/103620609
今日推荐