Skip to content

Commit 86d89a2

Browse files
Initial Commit
1 parent 0ec9d97 commit 86d89a2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package easyq;
2+
/* BY-M.NAVEEN
3+
* engineerscodes
4+
* code -Program for array rotation
5+
* sr.code-Ar2
6+
* moves zeros to end of the array
7+
* */
8+
import java.util.Arrays;
9+
import java.util.*;
10+
public class multiple_left_rotations // class name
11+
{ static Scanner nav=new Scanner(System.in); // calling Scanner and creating object nav
12+
static int array[],size,rotation[]={1,3,4,6},temp[],count=0;
13+
public multiple_left_rotations(int c)
14+
{ size=c;
15+
array=new int[size];
16+
}
17+
public static void rotation()
18+
{ rotation[count]=rotation[count]%size;
19+
temp=new int[rotation[count]];
20+
for(int i=0;i<rotation[count];i++)
21+
{
22+
temp[i]=array[i];
23+
}
24+
System.out.println("elements in array="+Arrays.toString(temp) +count);
25+
for(int i=rotation[count];i<size;i++)
26+
{
27+
array[i-rotation[count]]=array[i];
28+
}
29+
for(int i=0;i<rotation[count];i++)
30+
{
31+
array[size-1-i]=temp[i];
32+
}
33+
System.out.println("elements in array="+Arrays.toString(array));
34+
count++;
35+
if (count==size)
36+
return;
37+
else
38+
rotation();
39+
}
40+
41+
public static void input()
42+
{
43+
for(int i=0;i<array.length;i++)
44+
array[i]=nav.nextInt();
45+
System.out.println("element in array are::"+Arrays.toString(array));
46+
}
47+
public static void main(String arg[])
48+
{
49+
System.out.println("enter the size of the array");
50+
multiple_left_rotations n=new multiple_left_rotations(nav.nextInt());
51+
System.out.println("Enter the element of array");
52+
input();
53+
rotation();
54+
55+
56+
57+
58+
}
59+
60+
61+
}

0 commit comments

Comments
 (0)