-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 62.txt
More file actions
31 lines (27 loc) · 799 Bytes
/
Day 62.txt
File metadata and controls
31 lines (27 loc) · 799 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
29
30
31
import java.util.*;
class Main {
static int[] rotate(int[] array, int n, int k) {
k %= n;
while (k > 0) {
int temp = array[n - 1];
for (int i = n - 1; i > 0; i--) {
array[i] = array[i - 1];
}
array[0] = temp;
k--;
}
return array;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int array[] = new int[n];
for (int i = 0; i < n; i++)
array[i] = in.nextInt();
int k = in.nextInt();
in.close();
array = rotate(array, n, k);
for (int i = 0; i < n; i++)
System.out.print(array[i] + " ");
}
}