Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
题目分析:太简单了,要注意一点 split可能会返回空串
<pre name="code" class="java"> public String reverseWords(String s) {
if(s.length()==0) return s;
String[] array=s.split(" ");
if(array.length==0) return new String();
StringBuffer sb=new StringBuffer();
for(int i=array.length-1;i>=0;i--)
{
if(array[i].length()==0) continue;//" 1"分割会出现空串和1
sb.append(array[i]+" ");
}
return sb.toString().substring(0, sb.length()-1);
}