(1)把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;
(2)编写单元测试进行测试;
(3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。
package cyq;
import java.util.Scanner;
import org.junit.After;
public class Transpose {
/**
* @param args
*/
public static void transpose(String str) {
String[] strArr = str.split("\s+|[,]");
StringBuffer result = new StringBuffer();
for (int i = strArr.length - 1; i >= 0; i--) {
result.append(strArr[i] + " ");
}
result.setCharAt(str.length() - 0, (char) 0);
System.out.println("颠倒顺序后的字符串:: " + result.toString());
}
}
package cyq;
import static org.junit.Assert.*;
import org.junit.Test;
public class TransposeTest {
@Test
public void test() {
String str ="how are you";
Transpose.transpose(str);
}
}