Affluent Savvy
Photo by Sora Shimazaki Pexels Logo Photo: Sora Shimazaki

Is 22 a spy number?

Input number is 22. Let's check it by using the logic of Spy number. As we notice here both the sum value and product value are the same. Hence, 22 is a Spy number.

What is the strongest prayer?
What is the strongest prayer?

It is called the "Jesus Prayer", and it consists simply in uttering the single word "Jesus" (or "Lord Jesus", or "Lord Jesus Christ, have mercy on...

Read More »
What does the number 111 mean spiritually?
What does the number 111 mean spiritually?

If you see 111 or any variation of this, spiritual practitioners advise you to make sure you've set an intention and goal that you're working...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

A number is said to be a Spy number, if the sum of the digits of the given number is equal to the product of the digits of the given number. For more clarification, we have to first calculate the sum of the digits of the given number. After that we have to calculate the product of the digits of the given number. Then we have to compare both the sum value and product value, if they are the same then the given number is a spy number otherwise it is not a spy number. In this article, we will see how to check if a number is a Spy number by using Java programming language.

To show you some instances

Instance-1

Input number is 123.

Let’s check it by using the logic of Spy number.

The sum of the digits of 123 = 1 + 2 + 3 = 6 The product of the digits of 123 = 1 * 2 * 3 = 6 As we notice here both the sum value and product value are the same.

Hence, 123 is a Spy number.

Instance-2

Input number is 22.

Let’s check it by using the logic of Spy number.

The sum of the digits of 22 = 2 + 2 = 4 The product of the digits of 22 = 2 * 2 = 4 As we notice here both the sum value and product value are the same.

Hence, 22 is a Spy number.

Instance-3

Input number is 234.

Let’s check it by using the logic of Spy number.

The sum of the digits of 234 = 2 + 3 + 4 = 9 The product of the digits of 234 = 2 * 3 * 4 = 24 As we notice here both the sum value and product value are not same.

Hence, 234 is not a Spy number.

Algorithm

Step 1 − Get an integer number either by initialization or by user input. Step 2 − Then take a loop and using the loop extract the digits and calculate sum value and product value. Step 3 − Finally, when the loop ends you have the total sum value and product value. Step 4 − If both the sum value and the product value are equal to each other then we can print the result as the given number is a spy number otherwise the number is not a spy number.

Multiple Approaches

How do I protect my 401K from an economic collapse?
How do I protect my 401K from an economic collapse?

How to Protect Your 401(k) From a Stock Market Crash Protecting Your 401(k) From a Stock Market Crash. Don't Panic and Withdraw Your Money Too...

Read More »
What is the 1010 power?
What is the 1010 power?

1010 Meaning: Creation and Emptiness. Angel number 1010 represents space and silence. Emptiness is a source of creation… This powerful number...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

We have provided the solution in 2 different approaches.

By Using Static Input Value

By Using User Defined Method

Let’s see the program along with its output one by one.

Approach-1: By Using Static Input Value

In this approach one integer value will be initialized in the program and then by using the algorithm we can check whether a number is a spy number or not.

Example

public class Main { public static void main ( String args [ ] ) { int inputNumber , org , productValue = 1 , sumValue = 0 , digit ; inputNumber = 123 ; org = inputNumber ; while ( inputNumber > 0 ) { digit = inputNumber % 10 ; sumValue = sumValue + digit ; productValue = productValue * digit ; inputNumber = inputNumber / 10 ; } if ( sumValue == productValue ) System . out . println ( org + " is a spy number." ) ; else System . out . println ( org + " is not a spy number." ) ; } }

Output

123 is a spy number.

Approach-2: By Using User Defined Method

In this approach, an integer value will be initialized in the program and then we will call a user defined method by passing this input number as parameter. Inside the method we will check whether a number is a disarium number or not by using the algorithm.

Example

public class Main { public static void main ( String args [ ] ) { int inp = 123 ; if ( checkSpy ( inp ) ) System . out . println ( inp + " is a spy number." ) ; else System . out . println ( inp + " is not a spy number." ) ; } public static boolean checkSpy ( int inputNumber ) { int productValue = 1 , sumValue = 0 , digit ; while ( inputNumber > 0 ) { digit = inputNumber % 10 ; sumValue = sumValue + digit ; productValue = productValue * digit ; inputNumber = inputNumber / 10 ; } if ( sumValue == productValue ) return true ; else return false ; } }

Output

123 is a spy number.

In this article, we explored how to check a number whether it is a spy number or not in Java by using three different approaches.

What breaks a Taurus?
What breaks a Taurus?

According to Brown, one of the biggest things that would hurt Taurus the most is betrayal. They're extremely loyal to a fault and tend to put all...

Read More »
What is the 5 senses method shifting?
What is the 5 senses method shifting?

6 days ago The 5 Senses Method involves imagining your Dream Reality(DR) using all of your senses to shift, but with an added twist involving your...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
How does your body know death is near?
How does your body know death is near?

Periods of rapid breathing, and no breathing for brief periods of time, coughing or noisy breaths, or increasingly shallow respirations, especially...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
Can I get rich quick by investing?
Can I get rich quick by investing?

Yes, you can become rich by investing in the stock market. Investing in the stock market is one of the most reliable ways to grow your wealth over...

Read More »