@@ -0,0 +1,817 @@
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class ReverseWordsInString %7B%0A    public String reverseWords(String s) %7B%0A        s = s.trim();%0A        final String pattern = %22%5B %5D%7B2,%7D%22;    // find 2 or more adjacent spaces%0A        Pattern p = Pattern.compile(pattern);%0A        Matcher m = p.matcher(s);%0A        s = m.replaceAll(%22 %22);%0A        String%5B%5D words = s.split (%22 %22);%0A        StringBuilder temp = new StringBuilder();%0A        for (int i = words.length - 1; i %3E= 0; i--) %7B%0A            temp.append (words%5Bi%5D);%0A            if (i != 0) temp.append(%22 %22);%0A        %7D%0A        return temp.toString();%0A    %7D%0A    %0A    public static void main (String%5B%5D args) %7B%0A        ReverseWordsInString test = new ReverseWordsInString ();%0A        System.out.println (test.reverseWords (%22 Am   I insane?%22));%0A    %7D%0A%7D

Reverse words in input string