Skip to content

Commit aeab77f

Browse files
Create CyclicRotator.java
1 parent 6fd8e26 commit aeab77f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.javamultiplex.array.rotation;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
//Clockwise rotate an array by one
7+
public class CyclicRotator {
8+
9+
public static void main(String[] args) {
10+
11+
Scanner input = new Scanner(System.in);
12+
System.out.println("Enter array size : ");
13+
int size = input.nextInt();
14+
int[] arr = new int[size];
15+
System.out.println("Now enter elements of array");
16+
for (int i = 0; i < size; i++) {
17+
arr[i] = input.nextInt();
18+
}
19+
clockwiseRotate(arr,size);
20+
System.out.println(Arrays.toString(arr));
21+
input.close();
22+
}
23+
24+
private static void clockwiseRotate(int[] arr,int n) {
25+
26+
int temp=arr[n-1];
27+
for(int i=n-1;i>0;i--){
28+
arr[i]=arr[i-1];
29+
}
30+
arr[0]=temp;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)