Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReversWords {
- public static String reversed(String input) {
- String process = input;
- String result = "";
- while (process.length() > 0) {
- // условие когда осталось первое (оно же в результате последнее) слово и не осталось пробелов
- if (!process.contains(" ")) {
- result = result.concat(process);
- return result;
- }
- // находим последний слово и добавляем в результат
- result = result.concat(process.substring(process.lastIndexOf(" ") + 1) + " ");
- // удаляем последнее слово
- process = process.substring(0, process.lastIndexOf(" "));
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement