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 scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" ");
- int[] newInput = new int[input.length];
- int rotation = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < newInput.length; i++) {
- newInput[i] = Integer.parseInt(input[i]);
- }
- for (int m = 1; m <= rotation; m++) {
- int firstelement = newInput[0];
- for (int j = 0; j < newInput.length - 1; j++) {
- newInput[j] = newInput[j + 1];
- }
- newInput[newInput.length - 1] = firstelement;
- }
- for (int i = 0; i < newInput.length; i++) {
- System.out.print(newInput[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement