1.写一个Java程序,把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”; 2.编写单元测试进行测试; 3.用ElcEmma查看代码覆盖率,...

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

}

}

转载于:https://www.cnblogs.com/hh13/p/5326781.html

你可能感兴趣的:(1.写一个Java程序,把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”; 2.编写单元测试进行测试; 3.用ElcEmma查看代码覆盖率,...)