原题目
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
package excise;
public class T022 {
public static void main(String args[]) {
String test = "the sky is blue";
System.out.println(reverseWords(test));
}
public static String reverseWords(String s) {
String x[]=s.split(" ");
StringBuffer str = new StringBuffer();
for(int i=x.length-1;i>=0;i--){
str.append(x[i]).append(" ");
}
return str.toString();
}
}