Questions
Write a program to input a number and print whether or not it is a SPY number. A number
is said to be a SPY number if the sum of digits is same as product of digits. Eg. 123 is a
SPY number as the sum of digits(1+2+3) is same as product of digits(1*2*3).
Answers
Answered by
2
Answer:
import java.util.*;
public class Numbers{
public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int product = 1, sum = 0 , d, n;
n = sc.nextInt();
while (n>0)
{
d = n%10;
sum = sum + d;
product = product *d;
n = n/10;
}
if (sum == product){
System.out.println(“The number is a spy number”);
}else{
System.out.println(“The number is not a spy number”);
}
}
}
Similar questions