OneCompiler

Write a program to accept a number and check if it is a spy number

228

SPY NUMBER: is a number whose sum and product of the digits is same

Eg: 22
Sum =2+2 =4
Product =2
2 =4*

Eg: 1124
Sum =1+1+2+4 =8
Product =1
124 =8*

import java.util. * ;
public class spynumber {
public static void main(String[] args) {
int sum=0,product=1,n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
n=sc.nextInt();
int num=n;
while(num>0)
{
int d=num%10;
sum+=d;
product*=d;
num/=10;
}
if(sum==product)
System.out.println(n+" is a spy number");
else
System.out.println(n+" is not a spy number");
}
}

FOR CODE : CLICK >> https://onecompiler.com/java/3ygscumu8 TO FIND OUTPUT

SUPPORT US >> https://onethoughttechnology.blogspot.com (OFFICIAL WEBSITE)