write a menu driven program to check whether a number is a Spy number
Answers
Answered by
3
import java.util.Scanner;
public class SpyNumOrNot
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int num = in.nextInt();
int digit, sum = 0;
int num1 = num;
int prod = 1;
while (num > 0)
{
digit = num % 10;
sum += digit;
prod *= digit;
num /= 10;
}
if (sum == prod)
System.out.println(num1 + " is Spy Number");
else
System.out.println(num1 + " is not Spy Number");
}
}
Similar questions