File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66public class ReverseWordsInSentence {
77 public static void main (String [] args ) {
88 ReverseWordsInSentence obj =new ReverseWordsInSentence ();
9- // obj.logic1();
10- obj .logic2 ();
9+ obj .logic1 ();
10+ // obj.logic2();
1111 // obj.logic3();
1212 }
1313
@@ -16,13 +16,11 @@ public void logic1() {
1616 String s ="" ;
1717 char [] ch =str .toCharArray ();
1818 for (int i =0 ;i <ch .length ;i ++) {
19-
2019 int k =i ;
21-
2220 while (i <ch .length && ch [i ]!=' ' ) {
2321 i ++;
2422 }
25- for (int j =i -1 ;j >=k ;j --) {
23+ for (int j =i -1 ;j >=k ;j --) { // Reverse String logic
2624 s =s +str .charAt (j );
2725 }
2826 s =s +" " ;
@@ -34,10 +32,8 @@ public void logic2() {
3432 String str ="This is me" ; // siht si em
3533 String s ="" ;
3634 String [] words = str .split (" " );
37-
3835 for (int i = 0 ; i < words .length ; i ++) {
39- for (int j = words [i ].length ()-1 ; j >= 0 ; j --) {
40-
36+ for (int j = words [i ].length ()-1 ; j >= 0 ; j --) { // Reverse String logic
4137 s += words [i ].charAt (j );
4238 }
4339 s += " " ;
You can’t perform that action at this time.
0 commit comments