package Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main{
@SuppressWarnings("resource")
public static void main(String[] args){
// Scanner in=new Scanner(System.in);
// System.out.println("请输入字符串:");
String str="a friend in need is a friend
indeed";
// String str= in.next();//输入的字符串str
// str=str.replace('\'', ' ');
// str=str.replace(',', ' ');
// str=str.replace('.',' ');
String[] strings=str.split(" ");
Map<String,Integer> map=new
HashMap<String,Integer>();
List<String> list=new
ArrayList<String>();
for(String s:strings){
if(map.containsKey(s)){
int x=map.get(s);
x++;
map.put(s,x);
list.add(s);
}else{
map.put(s,1);
list.add(s);
}
}
int max=0;
String maxString=null;
for(String s:list){
int x=map.get(s);
if(x>max){
maxString=s;
max=x;
}
}
System.out.println("出现次数最多的单词为:"+maxString);
System.out.println("出现的次数为:"+map.get(maxString));
}
}