Friday , 18 January 2019
Home » ICSE Important Programs » Program to find frequency of every alphabet in a String

Program to find frequency of every alphabet in a String


Write a program to input a string (word). Convert it into lowercase letters. Count and print the frequency of each alphabet present in the string. The output should be given as:
Sample Input: Alphabets
Sample Output:
Alphabet             Frequency
a                              2
b                              1
e                              1
h                              1
l                               1
p                              1
s                              1
t                               1

Programming Code:

* The class AlphabetFreq inputs a string and counts the frequency of each alphabet present in it
* @author :
* @Program Type : BlueJ Program - Java

class AlphabetFreq
    public static void main(String args[])throws IOException
        BufferedReader br=new BufferedReader(new InputStreamReader(;
        System.out.print("Enter any string: ");
        String s = br.readLine();
        s=s.toLowerCase(); //converting the string into lowercase
        int l=s.length(); //finding the length of the string
        char ch;
        System.out.println("=========================="); //this is just for styling the look of the output
        /* Counting frequency of alphabets begins below */
        int count=0;
        for(char i='a'; i<='z'; i++)
                count = 0;
                for(int j=0; j<l; j++)
                    ch=s.charAt(j); //extracting characters of the string one by one
                    if(ch==i) //first checking the whole string for 'a', then 'b' and so on
                        count++; //increasing count of those aplhabets which are present in the string
                if(count!=0)//printing only those alphabets whose count is not '0'


Enter any string: ilovejavaforschool

Alphabet             Frequency
a                               2
c                               1
e                              1
f                               1
h                              1
i                                1
j                                1
l                                2
o                               4
r                                1
s                               1
v                               2

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks


  1. Amazing site.really helped a lot

  2. how can we count words instead if charcters?

    • System.out.print("Enter any sentence : ");
      String s = br.readLine();
      s = s + " ";
      int l = s.length();
      int c = 0;
      for(int i=0;i<l;i++)
                  if(s.charAt(i)==' ')
      System.out.println("Number of words = "+c);
  3. Thank you …..very much very useful ……i like this website

  4. Thanku very much very useful

  5. What is \t?How is it used here?

  6. thanx awesome code


  8. this really helped me alot thanks a ton!!!!

  9. awesome……..stuff…thanx really helped me

  10. awesome……..stuff…thanx really helped me..

Leave a Reply to kaushal Cancel reply

Your email address will not be published. Required fields are marked *