Fascinating Number in Java3 min read

In this java program tutorial, we will learn about the Fascinating Number and its implementation through Java. We will check whether the number Fascinating Number or not and also another program to find the find Fascinating Number within a given range in java.

What is Fascinating Number?

A number is said to be a fascinating number if it is (having at least 3 digits) multiplied by 2 and 3, and then both these product’s results are concatenated with the original number, then the new number contains all the digits from 1 to 9 exactly once. There could be any number of zeros and are ignored.

Example:
Consider a Number = 192
Then multiply it by two and 3
192 × 2 = 384
192 × 3 = 576
Concatenating the above twonumbers with the original number, we get:
“192” + “384” + “576” = 192384576 = result.
Now the final result contains all the digits from 1 to 9. Hence it is a Fascinating Number.


Procedure for Fascinating Number

  1. First, check if the entered/given number has three digits or not. If not, print “cannot be a Fascinating Number”.
  2. Else, Multiply the given number with 2 and 3.
  3. Then convert the product result into a string and Concatenate those strings along with the original number.
  4. Iterate the string that we get after concatenation and also keep the frequency count of the digits.
  5. Print “Not a Fascinating Number” if any of the digits (1 to 9) is missing or repeated.
  6. Else, print “It is a Fascinating Number”.

Java Program for Fascinating Number

1. Java Program to check whether a number is fascinating or not.

Output:


2. Java Program to find all the fascinating numbers between the given Range.

Output:


MORE

Java Program to check Krishnamurthy Number

In this tutorial, we will learn about Krishnamurthy numbers and write a Krishnamurthy Number program in Java. We will write two programs for Krishnamurthy number …
Read More

Java Program for ISBN Number

In this tutorial, we will learn about the ISBN (International Standard Book Number) and write a program to check for the ISBN Number in Java …
Read More

C++ Memory Management

Memory management refers to the process of managing the computer memory while assigning the space to the program’s variable to improve the overall performance. Requirement …
Read More

C++ Pointer to Pointer

As we know by now that a pointer stores the address of the pointed variable. But it is not the only use, pointer also stores …
Read More

C++ Passing Pointers to Functions

A function is a user-defined block of codes that executes some specific task assigned to it invoked by its name. If there is an argument …
Read More

C++ Null Pointer

We use a null pointer when we do not have the exact address to assign to a pointer. It is considered a good practice and …
Read More