The program will take a number as input and print how many times each digit occurs in the number. The frequency of the digits which are not present in the number will not be printed.
import java.util.*;
public class DigitFreq
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n, n2, c, d, i;
System.out.println("Enter a number: ");
n = sc.nextInt();
System.out.println("Frequency: ");
for(i=0;i<=9;i++)
{
n2 = n;
c=0;
while(n2!=0)
{
d = n2%10;
n2 = n2/10;
if(d==i)
c++;
}
if(c!=0)
System.out.println(i+" : "+c);
}
}
}