import java.util.*;
class
FrequencyOfCharacters
{
public static
void main(String[] args)
{
System.out.println("Enter the string");
String
s=new Scanner(System.in).nextLine();
frequency(s);
}
public static void
frequency(String str)
{
Character
c;
HashMap
for(int
i=0;i<str.length();i++)
{
c=str.charAt(i);
if(hm.containsKey(c))
hm.put(c,hm.get(c)+1);
else
hm.put(c,1);
}
Set
Iterator
while (keySetIterator.hasNext())
{
Character
key = keySetIterator.next();
System.out.println(key + " "
+ hm.get(key));
}
}
}
|
OutPut