zoukankan      html  css  js  c++  java
  • 1.写一个Java程序,把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”; 2.编写单元测试进行测试; 3.用ElcEmma查看代码覆盖率,要求覆盖率达到100%

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

    }

    }

  • 相关阅读:
    2020-03-23
    2020-03-22
    2020-03-21
    2020-03-20
    2020-03-19
    2020-03-18
    2020-03-17
    单元测试-java
    2020-03-16
    C语言拯救计划Day3-1之求一批整数中出现最多的个位数字
  • 原文地址:https://www.cnblogs.com/hh13/p/5326781.html
Copyright © 2011-2022 走看看