题解 | #统计一句话中重复单词的个数#
统计一句话中重复单词的个数
https://www.nowcoder.com/practice/2128e598b5a5407195c31175b5b33360
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();
//write your code here......
for(int i=0; i<line.length(); i++) {
char c = line.charAt(i);
if(Character.isLetter(c)) {
map.put(c, map.getOrDefault(c, 0) + 1);
}
}
for(Character key: map.keySet()) {
System.out.println(key + ":" + map.get(key));
}
}
}