Kodekraftt
/Blog
/Fascinating Number In Java With Explanation Definition Examples And Program
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

Fascinating Number in Java with Explanation, Definition, Examples, and Program

A Fascinating Number is a number which, when multiplied by 2 and 3 and then concatenated with itself, forms a string that contains all digits from 1 to 9 exactly once.

Fascinating Number in Java

A Fascinating Number is a special number that, when multiplied by 2 and 3, and all three results are concatenated together, produces a 9-digit string that contains all digits from 1 to 9 exactly once. Zero (0) must not appear in the final combined string.

Example

Example 1: 192

Multiply the number by 1, 2, and 3:

  • 192 × 1 = 192
  • 192 × 2 = 384
  • 192 × 3 = 576

Now concatenate them:


"192" + "384" + "576" = "192384576"

The result 192384576 contains all digits from 1 to 9 exactly once and is a valid Fascinating Number.


Example 2: 853

  • 853 × 1 = 853
  • 853 × 2 = 1706
  • 853 × 3 = 2559

Concatenate:


"853" + "1706" + "2559" = "85317062559"

This contains more than 9 digits and does not contain digits 1–9 exactly once. So, 853 is NOT a Fascinating Number.


Java Program to Check Fascinating Number


public class FascinatingNumber {

    // Function to check if a number is fascinating
    static boolean isFascinating(int num) {
        String concat = num + "" + (num * 2) + "" + (num * 3);

        // If length is not 9, it cannot be fascinating
        if (concat.length() != 9) return false;

        // Check if digits 1 to 9 appear exactly once
        for (char digit = '1'; digit <= '9'; digit++) {
            if (concat.indexOf(digit) == -1 || concat.indexOf(digit) != concat.lastIndexOf(digit)) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) {
        int num = 192;

        if (isFascinating(num)) {
            System.out.println(num + " is a Fascinating Number");
        } else {
            System.out.println(num + " is NOT a Fascinating Number");
        }
    }
}

Practice Challenges

  1. Print all Fascinating Numbers between 100 and 10,000.
  2. Modify the program to take user input and check the number.
  3. Update the program to show the concatenated result along with validation steps.

You might also like

Disarium Number in Java: Definition, Examples, and Complete Program

A detailed explanation of Disarium Numbers in Java with definition, examples, step-by-step logic, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Check Perfect Square in Java Without Using Math.sqrt() – Explanation, Logic, Examples, and Program

Learn how to check whether a number is a Perfect Square in Java without using Math.sqrt(). This guide explains the logic, provides examples, and includes an efficient program using iterative checking.

Spy Number in Java — Definition, Logic, Examples, and Program

Learn what a Spy Number is in Java with clear explanations and examples. This blog covers the definition, logic, step-by-step approach, and a clean Java program to check whether a number is a Spy Number. Includes practice challenges to improve your number theory skills.

Automorphic Number in Java: Definition, Explanation, and Step-by-Step Program

A clear and detailed guide on Automorphic Numbers in Java, including definition, examples, logic breakdown, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Sad Number in Java — Definition, Explanation, Examples, and Program

Learn what a Sad Number is in Java with clear explanation and logic. This blog covers the definition of a Sad Number, how it differs from a Happy Number, examples, and a complete Java program. Includes practice challenges to strengthen your number theory concepts.

Perfect Cube in Java with Explanation, Definition, Examples, and Program

A Perfect Cube is a number that can be expressed as the cube of an integer. This guide explains the concept with examples and provides a simple Java program to check if a number is a perfect cube.