Wap to find given no is spy no or not?
Answers
Answered by
4
❇
✔program to accept a number and check and display whether it is a Spy Number or not.
A Number is spy number if the sum of its digits equals the product of its digits.
Example : consider the number 1124
Sum of the digits = 1 + 1 + 2 + 4
Product of the digits = 1 * 1 * 2 * 4
Attachments:
Answered by
0
A number is spy if sum of the digits = product of the digits
Here’s your Java programming
import java.io.*;
public class spy
{
public static void main(Stringargs[])throwsIOException
{
System.out.println(“enter any number “);
int n = Integer.parseInt(input.readLine);
int s=0,p=1,d,k;
k=n;
while ( n!=0)
{
d=n%10;
n=n/10;
s+=d;
p*=d;
}
if (s==p)
System.out.println(k+” is a spy number”);
}
}
Here’s your Java programming
import java.io.*;
public class spy
{
public static void main(Stringargs[])throwsIOException
{
System.out.println(“enter any number “);
int n = Integer.parseInt(input.readLine);
int s=0,p=1,d,k;
k=n;
while ( n!=0)
{
d=n%10;
n=n/10;
s+=d;
p*=d;
}
if (s==p)
System.out.println(k+” is a spy number”);
}
}
Similar questions