0

PLEASE FIX THIS CODE

Write a program to reverse the word of sentence Example The cat is sleeping ehT tac si gnipeels https://code.sololearn.com/cZSN2aP9pHto/?ref=app

9th Feb 2019, 10:50 AM
Shiori san
Shiori san - avatar
3 Answers
0
Line 27 replace s1 by s2(s1 - current, s2 - reversed) Swap lines 28 and 29.
9th Feb 2019, 11:18 AM
Earl_Grey
Earl_Grey - avatar
+ 1
1. Split line to strings by space String[] arr = line.split(" "); 2. Reverse each string arr[i] = new StringBuilder(arr[i]).reverse().toString(); 3. Join strings together with space String result = String.join(" ", arr);
9th Feb 2019, 11:15 AM
Bartosz Pieszko
Bartosz Pieszko - avatar
0
Also you need to reverse the last word of sentence. I would put the code between 22- 26lines in a separate method and call it twice. Second time for the last word when we get the end of sentence.
9th Feb 2019, 11:26 AM
Earl_Grey
Earl_Grey - avatar