第二次 第二题

public class Demo {
2 public void reverse(String str) {
3 String[] wordsArray = str.split(" ");
4 System.out.print("单词颠倒输出: ");
5 for (int i = wordsArray.length - 1; i >= 0; i--) {
6 System.out.print(wordsArray[i] + " ");
7 }
8 }
9 }

JUnit单元测试类:

1 import static org.junit.Assert.*;
2 import org.junit.Test;
3
4 public class DemoTest {
5
6 @Test
7 public void testReverse() {
8 Demo demo = new Demo();
9 demo.reverse("Hello World Hello Java Hello Test");
10 }
11
12 }

原文地址:https://www.cnblogs.com/cwwwcc/p/5335448.html