## Computer Applications

Write a program to accept a number and check whether it is a 'Spy Number' or not. (A number is spy if the sum of its digits equals the product of its digits.)

Example: Sample Input: 1124

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

Product of the digits = 1*1*2*4 = 8

#### Java

#### Java Iterative Stmts

#### ICSE

33 Likes

### Answer

```
import java.util.Scanner;
public class KboatSpyNumber
{
public void spyNumCheck() {
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int num = in.nextInt();
int digit, sum = 0;
int orgNum = num;
int prod = 1;
while (num > 0) {
digit = num % 10;
sum += digit;
prod *= digit;
num /= 10;
}
if (sum == prod)
System.out.println(orgNum + " is Spy Number");
else
System.out.println(orgNum + " is not Spy Number");
}
}
```

### Output

Answered By

7 Likes

## Related Questions

Write a program to input a number. Check and display whether it is a Niven number or not. (A number is said to be Niven which is divisible by the sum of its digits).

Example: Sample Input 126

Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.

Example: Consider the number 59.

Sum of digits = 5 + 9 = 14

Product of digits = 5 * 9 = 45

Sum of the sum of digits and product of digits = 14 + 45 = 59Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, then display the message "Special two—digit number" otherwise, display the message "Not a special two-digit number".

You can multiply two numbers 'm' and 'n' by repeated addition method.

For example, 5 * 3 = 15 can be performed by adding 5 three times ⇒ 5 + 5 + 5 = 15Similarly, successive subtraction of two numbers produces 'Quotient' and 'Remainder' when a number 'a' is divided by 'b' (a>b).

For example, 5/2 ⇒ Quotient = 2 and Remainder = 1

Follow steps shown below:Process Result Counter 5 - 2 3 1 3 - 2 1 2 Sample Output: The last counter value represents 'Quotient' ⇒ 2

The last result value represents 'Remainder' ⇒ 1Write a program to accept two numbers. Perform multiplication and division of the numbers as per the process shown above by using switch case statement.

Using a switch statement, write a menu driven program to:

(a) generate and display the first 10 terms of the Fibonacci series

0, 1, 1, 2, 3, 5

The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.(b) find the sum of the digits of an integer that is input by the user.

Sample Input: 15390

Sample Output: Sum of the digits = 18

For an incorrect choice, an appropriate error message should be displayed.