Spy Number
✹ A spy number is a number where the sum of its digits equals the product of its digits.
For Example: 1124
è 1 + 1 + 2 + 4 = 8 (Sum of Digit)
1124 è1 X 1 X 2 X 4 = 8 (Product of Digit)
Sum of Digit & Product of Digit both are equal so it is Spy Number.
import java.util.*;
class SPY_NUMBER
{
public static void main(String
args[])
{
int n,digit, sum =
0,product = 1;
Scanner sc=new
Scanner(System.in);
System.out.println("Enter the Number = ");
n=sc.nextInt();
while (n > 0)
{
digit=n%10;
sum += digit; // sum of digits
product *= digit; //Product of digits
n = n/10;
}
if (sum == product) //Compare Sum & Product of Digits
System.out.println("The number is Spy Number");
else
System.out.println("The number is Not a Spy Number");
}}
class SPY_NUMBER
{
public static void main(String args[])
{
int n,digit, sum = 0,product = 1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number = ");
n=sc.nextInt();
while (n > 0)
{
digit=n%10;
sum += digit; // sum of digits
product *= digit; //Product of digits
n = n/10;
}
if (sum == product) //Compare Sum & Product of Digits
System.out.println("The number is Spy Number");
else
System.out.println("The number is Not a Spy Number");
}
No comments