Write a program in Java to check whether a given number is ‘Fascinating number’ or not.

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

Example: 192

Fascinating number

To concatenate, we first need to count the number of digits in the multiple of 2, then we multiply the original number with that much number of 10s and then we add the multiple of 2 to it.

We need to continue to concatenate multiple of 3 to the concatenated number.

To count the frequency of each digit in the concatenated number, we will use an array of size 10, in which each index will represent the digit and its value will be its count.

So let’s implement it in Java.

Output

Fascinating Nubmber Java program output

If you have any doubts or suggestion then comment below.

Leave a Reply

Close Menu