-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotateList.java
More file actions
28 lines (24 loc) · 820 Bytes
/
rotateList.java
File metadata and controls
28 lines (24 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package FML;
import java.util.Arrays;
import java.util.Scanner;
public class rotateList {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input1 = sc.nextLine();
//int input2 = sc.nextInt();
String list[] = input1.split(",");
int rotateIndex = sc.nextInt();
int[] rotatedList = new int[list.length];
for(int i=0;i<rotatedList.length;i++) {rotatedList[i] = Integer.parseInt(list[i]);}
for (int i = 0; i < rotateIndex; i++) {
int temp, lastElement;
lastElement = rotatedList[rotatedList.length - 1];
for (temp = list.length - 1; i > 0; i--) {
rotatedList[temp] = rotatedList[temp - 1];
rotatedList[0] =lastElement ;
}
}
System.out.print(Arrays.toString(rotatedList).replace("[", "").replace("]", "").replace(" ", ""));
sc.close();
}
}