import java.util.*;
class FrequencyCountOfChar
{
public static void main(String[] args) {
printAllCounts(args[0]);
}
static void printAllCounts(String input)
{
for( ; input.length() > 0 ; )
{
printFrequencyCount(input);
input = input.replace(""+input.charAt(0),"");
}
}
static void printFrequencyCount(String data)
{
int count = 0;
char temp = data.charAt(0);
for(int i = 0 ; i < data.length() ;i++)
{
if( temp == data.charAt(i) && i != (data.length() - 1))
{
count++;
}
if( temp == data.charAt(i) && i == (data.length() - 1))
{
count++;
System.out.println(temp + "=" + count);
}
else if( temp != data.charAt(i) && i == (data.length() - 1))
{
System.out.println(temp + "=" + count);
}
}
}
}
output :-
C:\Users\mulpk\Desktop>javac FrequencyCountOfChar.java
C:\Users\mulpk\Desktop>java FrequencyCountOfChar hellohi
h=2
e=1
l=2
o=1
i=1
No comments:
Post a Comment