SPYNUMBER:
A spy number is a number where the sum of its digits equals the product of its digits. For example, 1124 is a spy number, the sum of its digits is 1+1+2+4=8 and the product of its digits is 1*1*2*4=8.
/* java program to find given number is spynumber or not*/
import java.util.*;
public class SpyNumber
{
public static void main(String args[])
{
int no, pro, sum, digit;
pro = 1;
sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number to check spy number :");
no = sc.nextInt();
while(no != 0)
{
digit = no % 10;
pro = pro * digit;
sum = sum + digit;
no = no / 10;
}
if(sum == pro)
{
System.out.println("Spy Number");
}
else
{
System.out.println("Not Spy Number");
}
}
}
OUTPUT:
Enter a number to check spy number:
1124
Spy Number
Enter a number to check spy number:
1254
Not Spy Number