为了保证代码覆盖率,所以把两个功能分开成两个类,在main函数中调用
main函数:
package com.test.work;
public class all {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
test1 t1 = new test1();
test2 t2 = new test2();
}
}
第一个功能
package com.test.work;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class test1 {
String a = "Hello World My First Unit Test";
Map<String,Integer> strlist = new HashMap<String,Integer>();
String[] str = a.split(" ");{
for(int buff=0;buff < str.length;buff++){
if(strlist.containsKey(str[buff])){
int va = (Integer) strlist.get(str[buff]);
strlist.put(str[buff], ++va);
}else{
strlist.put(str[buff], 1);
}
}
for(Entry<String,Integer> s:strlist.entrySet()){
System.out.println(s);
}
}
}
第二个功能
package com.test.work;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class test2 {
String a = "how are you";
String[] str = a.split(" ");
StringBuffer s = new StringBuffer();{
for(int b =str.length-1;b>=0; b--){
s.append(str[b] + " ");
}
System.out.println(s);
}
}