Solved ProgramsISCClass 12Computer Science

Fascinating Number program Solved ISC practical 2021 Question 1

Fascinating Number program Solved ISC…: solved Java program for ISC Class 12 Computer Science with complete BlueJ code, explanation and sample output.

Updated
Solved Programs

Fascinating Number program

Frequency of letters

import java.util.*;
class Fascinating
{
    /* joins n, 2n and 3n: for 192 it returns "192384576" */
    String mergeNum(int n)
    {
        return Integer.toString(n) + Integer.toString(n * 2) + Integer.toString(n * 3);
    }

    /* a fascinating number's merged form contains every digit 1 to 9 exactly once (and no 0) */
    boolean isFascinating(int n)
    {
        String m = mergeNum(n);
        if (m.length() != 9)
            return false;
        for (char d = '1'; d <= '9'; d++)
        {
            if (m.indexOf(d) == -1)
                return false;
        }
        return true;
    }

    public static void main()
    {
        Fascinating obj = new Fascinating();
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the lower limit greater than 99");
        int lo = sc.nextInt();
        System.out.println("Enter the upper limit less than 10000");
        int ul = sc.nextInt();
        if (ul < lo || ul >= 10000 || lo <= 99)
        {
            System.out.println("INVALID INPUT");
            return;
        }
        int count = 0;
        System.out.println("THE FASCINATING NUMBERS ARE:");
        for (int j = lo; j <= ul; j++)
        {
            if (obj.isFascinating(j))
            {
                System.out.print(j + " ");
                count++;
            }
        }
        if (count == 0)
            System.out.print("NIL");
        System.out.println();
        System.out.println("FREQUENCY OF FASCINATING NUMBERS IS: " + count);
    }
}
Fascinating number program

http://www.youtube.com/trushnatej