反转单词

package reverse;

class Reverse{

public String reverse(String str) {
char[] c=str.toCharArray();
int len=c.length;
for(int i=0;i<len/2;i++) {
char tmp=c[i];
c[i]=c[len-i-1];
c[len-i-1]=tmp;
}
str=new String(c);
return str;
}
}
class ReverseWord{

public String reverseword(String str) {
Reverse r=new Reverse();
str=r.reverse(str);
String[] str1=str.split(" ");
StringBuffer sb=new StringBuffer();
for(String s:str1) {
sb.append(r.reverse(s)+" ");
}
return sb.toString();
}
}

public class ReverseWords {

public static void main(String[] args) {
String str="the sky is bule";
ReverseWord rw=new ReverseWord();
String s=rw.reverseword(str);
System.out.println(s);
}

}

posted @ 2018-05-05 00:45  特仑苏灬  阅读(129)  评论(0编辑  收藏  举报