Package com.company;
Import java.util.*;
Public class Mian{
Public static void main(String[] args){
System.out.println(“请输入一段英文”);
Scanner sc=new Scanner(System.in);
String strPara =sc.nextLine();
String[] strArray =strPara.split(“ ”);
Map<String,Integer> mapWords =new HashMap<String,Integer>();
For(String str :strArray)
{
If(!mapWords.containsKey(str))
{
mapWords.put(str,1);
}
else
{
Integer iCount=mapWords.get(str);
iCount++;
mapWords.put(str,iCount);
}
}
For(Map.Entry<String,Integer>me:mapWords.entrySet())
{
String strKey=me.getKey();
Integer iCount=me.getValue();
System.out.println(strKey+”出现了”+iCount+”次”);
}
}
}