java program to print the frequency of digits present in given number

Programming Example

Write a java program to accept an integer number and print the frequency of each digit present in the number .

Sample:

Input : 3255435

Output: 

Digit Frequency

2 1

3 2

4 1

5 3

Solution

import java.util.*;
class Frequency
{
    public static void main(String arr[])
    {
        Scanner sc=new Scanner(System.in);
        int number,i,count,digit,temp;
        System.out.println("Enter any Number : ");
        number=sc.nextInt();
         System.out.println("Digit\tFrequency");
        for(i=0;i<=9;i++)
        {
            count=0;
            temp=number;
            while(temp>0)
            {
                digit=temp%10;
                if(digit==i)
                {
                    count++;
                }
                temp=temp/10;
            }
            if(count>0)
            {
                System.out.println(i+"\t"+count);
            }
        }
    }
}
Output

Enter any Number : 

2231234

Digit Frequency

1 1

2 3

3 2

4 1

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