-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateLeftRight.java
More file actions
38 lines (32 loc) · 1006 Bytes
/
RotateLeftRight.java
File metadata and controls
38 lines (32 loc) · 1006 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
32
33
34
35
36
37
38
package Arrays;
import java.util.Arrays;
public class RotateLeftRight {
public static void main(String[] args) {
int []a= {10,20,30,40,50,60};
System.out.println(Arrays.toString(a));
// RotateLeft(a);
// RotateRight(a);
RotateLeftNthTime(a, 0);
}
public static void RotateLeft(int []a) {
int temp=a[0];
for(int i=0;i<a.length-1;i++) {
a[i]=a[i+1];
}
a[a.length-1]=temp;
System.out.println(Arrays.toString(a));
}
public static void RotateRight(int []a) {
int temp=a[a.length-1];
for(int i=a.length-1;i>0;i--) {
a[i]=a[i-1];
}
a[0]=temp;
System.out.println(Arrays.toString(a));
}
public static void RotateLeftNthTime(int a[],int n) {//DONT KNWO WHY THIS IS USED
for(int i=0;i<n;i++) {
RotateLeft(a);
}
}
}