没看懂这道题到底想怎么反转,反正过了
翻转单词顺序列
http://www.nowcoder.com/questionTerminal/3194a4f4cf814f63919d0790578d51f3
public String ReverseSentence(String str) {
if (str==null||str.trim().length()==0)
return str;
String res="";
int i=0;
for (;i<str.length();i++){
char c = str.charAt(i);
if (!(c>='a' && c<='z' || c>='A' && c<='Z')){
break;
}
}
if(i<str.length()){
String s1 = str.substring(0, i);
String s2 = str.substring(i+1);
String[] split = s2.split(" ");
for (int j=split.length-1;j>=0;j--){
res=res+split[j]+" ";
}
return (res+s1+str.charAt(i)).trim();
}else
return str;
}