}
*/
3.分析以下需求,并用代码实现:
(1)统计每个单词出现的次数
(2)有如下字符串"If you want to change your fate I think you must come to the dark horse to learn java"(用空格间隔)
(3)打印格式:
to=3
think=1
you=2
//........
/*
public static void main(String[] args) {
String s1 = "If you want to change your fate I think you must come to the dark horse to learn java";
String[] s2 = s1.split(" "); //将字符串切割字符数组
HashMap<String, Integer> hm= new HashMap<>(); //创建map集合
for (String st : s2) {
hm.put(st, hm.containsKey(st) ? hm.get(st) + 1 : 1); //遍历字符串数组,将字符添加到集合的键中,如果有重复,值加1
}
for (String s : hm.keySet()) {
System.out.println(s + " = " + hm.get(s)); //遍历集合
}
}
*/