Write a program in Java to input a number and check that number is Spy Number or not .
Use while loop. [A number is said to be a Spy Number if the sum of all the digits is equal to the product of all the digits. Example :1124 is a Spy number, Sum of digits (1+1+2+4)=8 is the same as product of its digits(1*1*2*4)=8.]
Don't post irrelevant things regarding the answer if you don't know please
Answers
Answered by
8
Answer:
import java.util.*;
public class spy
{
public static void main(String[]args)
{
int sum=0,product=1;
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int e=a;
int r=0;
while(a>0)
{
r=a%10;
product=product*r;
sum=sum+r;
a=a/10;
}
if(product==sum)
{
System.out.println("Spy ");
}
else
System.out.print("Not a spy");
}
}
Explanation:
Hope it helps
Similar questions