import java.util.*;
class FindFrequencyExample2 {
public static void main
(String args
[]) { // given string
String str
= "ScAaler by interviewbit"; // counter array to store the frequency of each character.
int freq[] = new int[str.length()];
// convert the string into character array
// store it in ch[]
char ch[] = str.toCharArray();
// traverse through each character in the ch[] array
for(int i=0;i<ch.length-1;i++){
// set freq[i] as 1
// for the first time visiting each new character
freq[i]=1;
// iterate through the rest of the characters
// ScAaler by interviewbit";
for(int j=i+1;j<ch.length;j++)
{
// if more ch[i] characters are present
if(ch[i]==ch[j])
{
// increase the count by 1
freq[i]++;
// set ch[j] to 0 to avoid counting visited characters
ch[j]='0';
}
}
}
// traverse through the freq array
for (int i = 0; i < freq.length; i++)
{
// if characters in ch[] array is not '0' and ' '
if(ch[i]!='0' && ch[i]!=' ')
{
// print the character along with its frequency
System.
out.
println(ch
[i
]+" - "+freq
[i
]); }
}
}
}