Q.READ THE FOLLOWING SOLUTION OF A PROGRAM WRITTEN IN JAVA AND ANSWER THE QUESTION THAT FOLLOWS:
WAP a java program to accept an integer number and print the frequency of each digit present in the number .
Sample:
Input : 323
Output:
Digit Frequency
2 1
3 2
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);
}
}
}
}
QUESTION: IN THIS PROGRAM WHY IS IT NECESSARY TO STORE THE NUMBER ENTERED BY THE USER IN TEMP VARIABLE?
Answers
Answered by
0
Explanation:
1. Buzz number
2. automorphic number
Enter your choice : 2
Enter number : 625
625 is automorphic
Similar questions