//Wap to accept a number and check whether it is a Spy Number or not.
// A number is spy if the sum of its digits equal the product of its digits.
//example 1124
//sum of the digits = 1+1+2+4=8
//product of the digits = 1x1x2x4=8
//8==8 so, 1124 is a spy number
import java.util.*;
class spy
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int n,r,pro=1,sum=0;
System.out.println("Enter a number:");
n=sc.nextInt();
while(n>0)
{
r=n%10;
sum=sum+r;
pro=pro*r;
n=n/10;
}
if(sum==pro)
System.out.println("It is a Spy number");
else
System.out.println("It is not a Spy number");
}
}
No comments:
Post a Comment
any problem in any program comment:-