08 September 2018

Java Program to find frequency count of letters in a given text

//Program to find frequency count of letters in a given text
import java.util.*;
class fcount
     {
   public static void main(String args[])
      {
    char ch;
    String s;
    int i,f=0;
    System.out.println(" Enter a string : ");
    Scanner obj=new Scanner(System.in);
    s=obj.nextLine();
    char a[]=s.toCharArray();
    System.out.println("Enter a character to find its frequency : ");
    ch=obj.next().charAt(0);
    for(i=0;i<a.length;i++)
       {
        if(ch==a[i])
            f++;
       }
    System.out.println("\n Frequency count of "+ch+" is : "+f);
    System.out.println();
     }
}
The Output will be similar to this

 when you enter a character which is not entered in the string

Similar program:-
Java Program to find word count in a given text



           

No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...