Write a Java program to find the frequency of each digit in a given number.
PROGRAM :
import java.util.Scanner;
public class freq
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to be checked.");
int i,j,c;
int n=sc.nextInt();
System.out.println("No Freq");
for(i=0;i<=n;i++)
{
c=0;
for(j=n;j>0;j=j/10)
{
if(j%10==1)
c++;
}
if(c>0)
System.out.println("Freq of "+i+" is "+c);
}}
}
/*
Output :
Enter the number to be checked : 12121
Freq of 1 is 4
Freq of 2 is 2