Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ArrayRotation {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] input = sc.nextLine().split(" ");
- int n = Integer.parseInt(sc.nextLine());
- n = n % input.length;
- for (int i = 0; i < n ; i++) {
- String firstElement = input[0];
- for (int k = 0; k < input.length - 1; k++) {
- input[k] = input[k + 1];
- }
- input[input.length - 1] = firstElement;
- }
- for (int i = 0; i < input.length; i++) {
- System.out.print(input[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement