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