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-reverse a string
5+ * sr.code-St1
6+ *
7+ * */
8+ import java .util .Arrays ;
9+ import java .util .*;
10+ public class reverse_an_string //class name
11+ { static Scanner nav =new Scanner (System .in );// calling Scanner and creating object nav
12+ static String array [],str ,ch ; // class instances variables
13+ static int size ;
14+ public reverse_an_string () // constructor
15+ {
16+ size =array .length ;//intialization of variables
17+ }
18+ public static void reverse () //method to reverse String array
19+ {
20+ for (int i =0 ;i <size /2 ;i ++)
21+ {
22+ ch =array [i ];
23+ array [i ]=array [size -1 -i ];
24+ array [size -1 -i ]=ch ;
25+
26+ }
27+ System .out .println (" reverse array --" +Arrays .toString (array ));
28+ print ();
29+ }
30+ public static void print () //method to display
31+ { System .out .println ("element in array-" );
32+ for (int i =0 ;i <size ;i ++)
33+ {
34+ System .out .print (" " +array [i ]);
35+ }
36+ }
37+ public static void main (String arg []) //main mathod
38+ {
39+ System .out .println ("Enter the the string" );
40+ str =nav .nextLine ();
41+ System .out .println (" string -" +str );
42+ array =str .split ("" );
43+ reverse_an_string n =new reverse_an_string ();
44+ reverse ();
45+ }
46+
47+ }
You can’t perform that action at this time.
0 commit comments