Computer Science, asked by anisuddinkhan6848, 4 months ago

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 product of its digits is 1^ * 1^ * 2^ * 4=8 Write a Java program to input a number and to find whether it is a spy number or not.​

Answers

Answered by amansarrafas24payxgs
4

Answer:

import java.util.*;

class Spy

{

public void main()

{

Scanner sc = new Scanner (System.in);

System.out.println("Enter a number: ");

int n = sc.nextInt();

int rem,sum = 0,prod = 1;

for(int i = n;i > 0;i/=10)

{

rem = i%10;

sum+=rem;

prod*=rem;

}

if(sum == prod)

{

System.out.println("It is a Spy Number");

}

else

{

System.out.println("It is not a Spy Number);

}

}

}

I hope you find it useful... If you have any query do comment, I will try to solve it...

Similar questions