Reverse all the words in a string
Anonymous
package asaf; public class ReverseWordsInString { public static void main(String[] args) { System.out.println(reverse("Reverse all the words in a string")); } private static String reverse(String s) { String result = ""; String space = ""; for (String word : s.split(" ")) { result = word + space + result; space = " "; } return result; } }
Check out your Company Bowl for anonymous work chats.