Skip to content

Commit 67cbf49

Browse files
Initial Commit
1 parent d7746b5 commit 67cbf49

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.*;
9+
public class reverse_an_array // class name
10+
{ static Scanner nav=new Scanner(System.in);// calling Scanner and creating object nav
11+
static int array[],size,temp; // class instances variables
12+
public reverse_an_array(int c) // constructor
13+
{ size=c;
14+
array= new int[size]; //intialization of variables
15+
}
16+
public static void reverse() //method to reverse the array
17+
{
18+
for(int i=0;i<size/2;i++) // i<size/2 this must ,if i<=size than it will again give youn samw array
19+
{
20+
temp=array[i];
21+
array[i]=array[size-1-i];
22+
array[size-1-i]=temp;
23+
}
24+
System.out.println("the rever of the array"+Arrays.toString(array));
25+
}
26+
public static void input() // method to enter element in array
27+
{
28+
for(int i=0;i<size;i++)
29+
array[i]=nav.nextInt();
30+
System.out.println("elements of array"+Arrays.toString(array));
31+
reverse();
32+
33+
}
34+
public static void main(String arg[]) // main method
35+
{
36+
System.out.println("enter the size of the array");
37+
reverse_an_array n=new reverse_an_array(nav.nextInt());
38+
System.out.println("Enter the element of array");
39+
input();
40+
}
41+
42+
}

0 commit comments

Comments
 (0)