icse-promo

Question

Write a program to input a string in uppercase and print the frequency of each character.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class program9
{
	public static void main(String[]args)
	{
	    int len=0,count=0;
		Scanner sc=new Scanner(System.in);
		System.out.print("Enter a string ");
		String sen=sc.nextLine();
		sen=sen.toUpperCase();
		len=sen.length();
		System.out.println("Characters:Frequency");
		for(char j='A';j<='Z';j++)
		{	
			for(int i=0;i< len;i++)
			{
				if(sen.charAt(i)==j)
				{
					count++;
			    }
			}
			if(count>0)
			{
				System.out.println(j+"	 :	"+count);
				count=0;
			}
		}
	}
}


				
			

Coding Store

Leave a Reply

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