package cn.huang.main;
import cn.huang.word.WordDown;
public class Demo {
public static void main(String[] args) {
String strWords="how are you";
WordDown wd=new WordDown();
wd.OutputResult(strWords);
}
}
package cn.huang.word;
public class WordDown {
public void OutputResult(String strWords){
String[] words_Array = strWords.split(" ");
int arrLength=words_Array.length;
StringBuffer result = new StringBuffer();
for(int i =arrLength -1;i >=0; i--){
result.append(words_Array[i] + " ");
}
result.setCharAt(strWords.length()-0, (char) 0);
System.out.println("颠倒顺序后的结果为:"+result.toString());
}
}
单元测试
package cn.huang.word;
import static org.junit.Assert.*;
import org.junit.Test;
public class WordDownTest {
public void test() {
String strWords="abc mln xyz";
WordDown target=new WordDown();
target.OutputResult(strWords);
}
}