wap in java to input a no. and check and print whether it is a factorial of its digits is equal to the no.
Answers
Answered by
0
import java.util.*;
public class SpecialNumberCheck
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to be checked.");
int num=ob.nextInt();
int sum=0;int temp=num;
while(temp!=0)
{
int a=temp%10;int fact=1;
for(int i=1;i<=a;i++)
{
fact=fact*i;
}
sum=sum+fact;
temp=temp/10;
}
if(sum==num)
{
System.out.println(num+" is a Special Number.");
}
else
{
System.out.println(num+" is not a Special Number.");
}
}
}
Similar questions
Math,
17 days ago
Environmental Sciences,
17 days ago
English,
1 month ago
Math,
9 months ago
Social Sciences,
9 months ago
History,
9 months ago