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
3 odpowiedzi
0
Line 27 replace s1 by s2(s1 - current, s2 - reversed)
Swap lines 28 and 29.
+ 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);
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.