Question
program to count frequency of characters in given sentence.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class frequencyOfCharactersInSentence
{
public static void main(String[] args)
{
String sen="";
char ch=' ',ch1=' ';
int i=0,len=0,count=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence");
sen = sc.nextLine();
sen=sen.toUpperCase();
len=sen.length();
for(ch='A';ch<='Z';ch++)
{
count=0;
for(i=0;i< len;i++)
{
ch1=sen.charAt(i);
if(ch1==ch)
{
count++;
}
}
System.out.println(ch+":"+count);
}
}
}