反转单词

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);
}

}

猜你喜欢

转载自www.cnblogs.com/smailjunk/p/8993315.html

相关文章