-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveArray.java
More file actions
60 lines (44 loc) · 1.32 KB
/
MoveArray.java
File metadata and controls
60 lines (44 loc) · 1.32 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Arrays;
import java.util.Arrays;
public class MoveArray {
public static void rotateRight(int []a) {
System.out.println("New Array A");
System.out.println(Arrays.toString(a));
for(int i=0;i<a.length-1;i++) {
int temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
System.out.println("Rotate Left by 1");
System.out.println(Arrays.toString(a));
}
public static void moveArray(int []a,int []b) {
for(int i=0;i<a.length;i++) {
b[i]=a[i];
}
System.out.println("Array A="+Arrays.toString(a));
System.out.println();
System.out.println("After Importing A into B");
System.out.println("Array B="+Arrays.toString(b));
System.out.println();
}
public static void rotateLeft(int []b) {
System.out.println("Now Move Arrays B to Left 2 Times");
int temp = b[0];
for(int k=0; k<=3;k++) {
for(int j=b.length-1;j>=1;j-- ){
int val=b[j];
b[j]=b[j-1];
b[j-1]=val;
}
}
System.out.println(Arrays.toString(b));
}
public static void main(String[] args) {
int []a= {1,2,3,4,5,6};
int []b=new int[a.length];
moveArray(a,b);
rotateLeft(b);
rotateRight(a);
}
}