java program to pass an integer as argument and print the frequency of each digit in it

Programming Example

Write a program to pass an integer as argument, and print the frequency of each digit in it.

Solution

class Frequency
{
	public static void main(int n)
	{
		int i,c,d,j;
		for(i=0;i<=9;i++)
		{
			c=0;
			for(j=n;j>0;j=j/10)
			{
				d=j%10;
				if(d==i)
					c++;
			}
			if(c>0)
				System.out.println(“Frequency of “+i+”=”+c);
		}
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad