MiniMi2022

Rotate list

Feb 15th, 2022 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RotateList {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.         String[] list = myScan.nextLine().split(",");
  7.         int n = Integer.parseInt(myScan.nextLine());
  8.         for (int i = 0; i < n; i++) {
  9.             String[] rotateList = new String[list.length];
  10.             for (int j = 1; j < list.length; j++) {
  11.                 rotateList[j - 1] = list[j];
  12.             }
  13.             rotateList[list.length - 1] = list[0];
  14.             for (int j = 0; j < list.length; j++) {
  15.                 list[j] = rotateList[j];
  16.             }
  17.         }
  18.         System.out.println(String.join(",", list));
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment