??????????????????????
???????????? ???????[ 2016/4/8 11:48:08 ] ??????????????? ???????
????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?????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11