import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class CheckString
{
public static void main(String args[])
{
String read=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
read=br.readLine();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Map map=new HashMap();
char c=' ';
for(int i=0;i<read.length();i++)
{
c=read.charAt(i);
if(map.containsKey(c))
{
map.put(c, new Integer(((Integer)map.get(c)).intValue()+1));
}
else
{
map.put(c, 1);
}
}
Collection<Integer> col=map.values();
Iterator<Integer> ite=col.iterator();
int max=0;
while(ite.hasNext())
{
int k=ite.next();
if(max<k)
{
max=k;
}
}
System.out.println("输入的字符串中字母最多出现"+max+"次!");
Set set=map.entrySet();
Iterator<Map.Entry<Character, Integer>> i=set.iterator();
Map.Entry<Character, Integer> entry;
while(i.hasNext())
{
entry=i.next();
if(entry.getValue()==max)
{
System.out.println("出现最多次数的字母有"+entry.getKey());
}
}
}
}
判断输入的一行字符串中出现次数最多的字母
最新推荐文章于 2023-10-29 10:45:54 发布