/**
*
* @author 吴思婷
* 2016-4-02
* WordDaoxu类用来将单词次序颠倒
* 假设单词之间用空格隔开,不考虑句子中的" . "和" ' "等符号,以及全角的情况
*/
public class WordDaoxu {
public String DaoxuOrder(String Words){
String[] wordsArray = Words.split("\\s");
StringBuffer result = new StringBuffer();
for(int i = wordsArray.length -1;i >=0; i--){
if("".equals(wordsArray[i].trim())){
continue;
}
result.append(wordsArray[i] + " ");
}
return result.toString();
}
}
import static org.junit.Assert.*;
import org.junit.Test;
public class WordDaoxuTest {
@Test
public void ReverseOrder(){
System.out.println("原英语句子为:\n"+"There is a pretty girl !");
System.out.println("句子单词倒序后为:");
String str="There is a pretty girl !";
WordDaoxu wordFreq=new WordDaoxu();
System.out.println(wordFreq.DaoxuOrder(str));
}
}