????1?? ????????????????????????
??????1??д???????????????????????и?????????????????????????????????????????????????????????????“Hello World My First Unit Test”????
1 import java.util.ArrayList;
2 import java.util.Collections;
3 import java.util.Comparator;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.Scanner;
8 import java.util.Map.Entry;
9
10 public class Count {
11     private static String str;
12     public  Count (String str){
13         Count.str=str;
14     }
15     public static void main(String[] args) {
16         System.out.print("?????????????????????");
17         Scanner in=new Scanner(System.in);
18         str = in.nextLine();
19         count(str);
20
21     }
22
23     public static void count(String str){
24         String[] items = str.split(" ");
25         Map<String?? Integer> map = new HashMap<String?? Integer>();
26         for (String s : items) {
27             if (map.containsKey(s))
28                 map.put(s?? map.get(s) + 1);
29             else {
30                 map.put(s?? 1);
31             }
32         }
33         List<Entry<String?? Integer>> list = new ArrayList<Entry<String?? Integer>>();
34         for (Entry<String?? Integer> entry : map.entrySet()) {
35             list.add(entry);
36         }
37         Collections.sort(list?? new EntryComparator());
38
39         for (Entry<String?? Integer> obj : list) {
40             System.out.println(obj.getKey() + " " + obj.getValue());
41         }
42     }
43 }
44
45 class EntryComparator implements Comparator<Entry<String?? Integer>> {
46     public int compare(Entry<String?? Integer> o1?? Entry<String?? Integer> o2) {
47         return o1.getValue() > o2.getValue() ? 0 : 1;
48     }
49 }
??????2????д?????????в????
import org.junit.Test;
public class CountTest {
@Test
public void testCount() throws Exception {
String str="i love you! and you? ";
Count.count(str);
}
}
??????3????ElcEmma?????????????????????

??????1??????????????е????????????????????????“how are you”?????“you are how”??
1 import java.util.Scanner;
2
3 public class Reverse{
4
5     public static void main(String[] args) {
6         Scanner input = new Scanner(System.in);
7         System.out.print("?????????????????????");
8         String str = input.nextLine();
9         Reverse.reverse(str);
10     }
11     public static void reverse(String str){
12         String[] strArr = str.split("\s+|[??]");
13         StringBuffer result = new StringBuffer();
14         for(int i = strArr.length -1;i >=0; i--){
15             result.append(strArr[i] + " ");
16         }
17
18         result.setCharAt(str.length()-0?? (char) 0);
19         System.out.println("?????????:  "+result.toString());
20
21     }
22 }
??????2????д?????????в????
1importorg.junit.After;
2importorg.junit.Test;
3publicclassReverseTest{
4
5@Test
6publicvoidtest()throwsException{
7Stringstr="howareyou";
8Reverse.reverse(str);
9}
10
11}
??????3????ElcEmma?????????????????????