public static void main(String[] args)
{
Map <String ,Integer> m =new HashMap<String , Integer>();
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
char c=str.toCharArray();
for(int i=0;i<c.lenght;i++)
{
if(m.containsKey(c[i]+""))
m.put(c[i]+"",++num);
else
num=1;
m.put(c[i]+"",num);
}
System.out.println(m);
}
原文:http://www.cnblogs.com/liuruiguang/p/5947556.html