Advertisement
deyanmalinov

04. Array Rotation

Feb 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package DPM;
  2. import java.util.*;
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String [] nums = scan.nextLine().split(" ");
  7.         int rot = Integer.parseInt(scan.nextLine());
  8.         rot= rot % nums.length;
  9.         for (int i = 0; i < rot; i++) {
  10.             String ele = nums[0];
  11.             for (int j = 0; j < nums.length-1; j++) {
  12.                 nums[j] = nums[j+1];
  13.             }
  14.             nums[nums.length-1] = ele;
  15.         }
  16.         for (String num : nums){
  17.             System.out.print(num+" ");
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement