Write a program to accept a number and check if its a spy number (in java)
ex. sum of digits = product of digits 123=1+2+3=6,1*2*3=6
icse class 10th
i will mark you brainliest and follow you if you give me a correct answer
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class SpyNumber
{
public static void main(String[] args)
{
int n,product=1,sum=0;
int ld;
// create object of scanner.
Scanner sc = new Scanner(System.in);
// you have to enter number here.
System.out.print("Enter the number :" );
// read entered number and store it in "n".
n=sc.nextInt();
// calculate sum and product of the number here.
while(n>0)
{
ld=n%10;
sum=sum+ld;
product=product*ld;
n=n/10;
}
// compare the sum and product.
if(sum==product)
System.out.println("Given number is spy number");
else
System.out.println("Given number is not spy number");
}
}
Similar questions