Problem: Write a Java program to check whether a given number is a Fascinating number or not.

A Fascinating number is the number which when combined with its multiple of 2 and 3 results into a number that consists of all digits from 1 to 9 exactly once.

Example: 192

Fascinating number

Steps to Check Fascinating number in Java:

  1. Input a number.
  2. Compute its multiple of 2 and 3.
  3. Concatenate the multiple calculated in the previous step with the input number.
  4. Count the frequency of each digit in the concatenated number.
  5. Check if all the counts are exactly 1.
  6. If so, then the input number is a fascinating number otherwise not.

Here is the Java program, which implements the above step to verify whether the input number is fascinating number or not:


Enter a number
Fascinating Number


To concatenate the multiples with the input number, we use the count of digits as follows:

We store the count of each digit in an array and then examine the array whether all the counts are 1 or not.

We then print the result depending on the result whether the above conditions were satisfied or not.

Leave a Reply

five + twelve =