Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 5 months ago

Please solve this program.
.
♦ Spamming not allowed
♦ Spamming will cause huge loss to spaammer.​

Attachments:

Answers

Answered by anindyaadhikari13
5

Required Answer:-

Question:

  • Write a program to accept a number and display whether it is a spy number or not.

Solution:

Here is the code.

import java.util.*;

public class SpyNumber {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n, s=0, p=1, d;

System.out.print("Enter a number: ");

n=sc.nextInt();

while(n!=0)

{

d=n%10;

s+=d;

p*=d;

n/=10;

}

if(s==p)

System.out.println("Number is a spy number.");

else

System.out.println("Number is not a spy number.");

sc.close();

}

}

Explanation:

A number is said to be a spy number if the sum of the digits of the number is equal to the product of the digits.

For example, if the number is 1124

Sum of digits = 1 + 1 + 2 + 4 = 8

Product of digits = 1 × 1 × 2 × 4 = 8

Hence, 1124 is a spy number.

In this program, we will calculate the sum and product of the digits and store them in s and p variable. At last, we will check if s == p. As per the condition, we will display if its spy number or not.

Output is attached.

Attachments:
Answered by JohnRobinson
24

Bro sorry for spamming in your question

Bro I am Iniyavan !! see my Answers! all are explained

Attachments:
Similar questions