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+ # https ://www.facebook.com/hitesh.parashar.908/posts/109890874217667
2+ # submitted by hitesh
3+
4+
5+
6+ public class Example
7+ {
8+ public void reverseWordInMyString (String str )
9+ {
10+ /* The split() method of String class splits
11+ * a string in several strings based on the
12+ * delimiter passed as an argument to it
13+ */
14+ String [] words = str .split (" " );
15+ String reversedString = "" ;
16+ for (int i = 0 ; i < words .length ; i ++)
17+ {
18+ String word = words [i ];
19+ String reverseWord = "" ;
20+ for (int j = word .length ()-1 ; j >= 0 ; j --)
21+ {
22+ /* The charAt() function returns the character
23+ * at the given position in a string
24+ */
25+ reverseWord = reverseWord + word .charAt (j );
26+ }
27+ reversedString = reversedString + reverseWord + " " ;
28+ }
29+ System .out .println (str );
30+ System .out .println (reversedString );
31+ }
32+ public static void main (String [] args )
33+ {
34+ Example obj = new Example ();
35+ obj .reverseWordInMyString ("Welcome to BeginnersBook" );
36+ obj .reverseWordInMyString ("This is an easy Java Program" );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments