I'm struggling with quite annoying thing. I'm working on Letter Frequency counter which checks the string or a text file and outputs a total number for each letter from the alphabet e.g. string stack would produce
s = 1, t = 1, a = 1, c = 1, k = 1.
Now I have managed to implement those functions and everything works, however now, I'll need to extract the data from FOR loop in order to print the pattern
for(int i=0; i<26; i++)
{
for(int j=0; j<l; j++)
{
ch=s.charAt(j); //extracting characters of the string one by one
if(ch==alph[i]) //first checking the whole string for 'a', then 'b' and so on
freq[i]++; //increasing count of those alphabets which are present in the string
}
}
Then after this loop one which checks everything and prints each letter from the loop
for(int i=0; i<26; i++)
{
if(freq[i]!=0) //printing only those alphabets whose count is not '0'
System.out.println(alph[i]+freq[i]);
}
The pattern would have to look like something along these lines
A XXX
B X
C XXXXXX
D XXX
....
Y XXX
Z XX
So for each letter there's an X which represent "1" X could be replaced with anything like #.
Aucun commentaire:
Enregistrer un commentaire