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