File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
array/geeksforgeeks/rotation Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments