正则表达式中最常用的词
import java.util.Map;//时代Java公众号 - N o w J a v a . c o m import java.util.Scanner; import java.util.TreeMap; public class MostfrequentWord { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String[] text = scn.nextLine().toLowerCase().split("\\W+"); TreeMap<String,Integer> mostFrequentWord = new TreeMap<>(); int maxCounter = 0; for (String word : text) { Integer count = mostFrequentWord.get(word); if(count == null){/**时 代 Java - nowjava.com**/ count = 0; } if(count + 1 > maxCounter){ maxCounter = count + 1; } mostFrequentWord.put(word,count + 1); } for (Map.Entry<String,Integer> max : mostFrequent