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

    }

    }

  • 相关阅读:
    1822. Sign of the Product of an Array
    1828. Queries on Number of Points Inside a Circle
    1480. Running Sum of 1d Array
    C++字符串
    Git&GitHb学习记录
    54. Spiral Matrix
    104. Maximum Depth of Binary Tree
    110. Balanced Binary Tree
    136. Single Number
    19、泛型入门
  • 原文地址:https://www.cnblogs.com/hh13/p/5326781.html
Copyright © 2020-2023  润新知