Categories
Class 11 Class 12

Fascinating Number in Java ISC Practical 2021

A Fascinating number is one which when multiplied by 2 and 3 and then, after the results are concatenated with the original number, the new number contains all the digits from 1 to 9 exactly once. There can be any number of zeroes and are to be ignored.

Example: 273
273 × 1 = 273
273 × 2 = 546
273 × 3 = 819

Concatenating the results we get, 273546819 which contains all digits from 1 to 9 exactly once.

Thus, 273 is a Fascinating number.

Accept two positive integers m and n, where m must be less than n and the values of both ‘m’ and ‘n’ must be greater than 99 and less than 10000 as user input. Display all Fascinating numbers that are in the range between m and n (both inclusive) and output them along with the frequency, in the format given below:

Test your program with the following data and some random data:

Example 1:
INPUT:
m = 100
n = 500
OUTPUT:
THE FASCINATING NUMBERS ARE:
192 219 273 327
FREQUENCY OF FASCINATING NUMBERS IS: 4

Example 2:
INPUT:
m = 900
n = 5000
OUTPUT:
THE FASCINATING NUMBERS ARE:
1902 1920 2019 2190 2703 2730 3027 3270
FREQUENCY OF FASCINATING NUMBERS IS: 8

Example 3:
INPUT:
m = 400
n = 900
OUTPUT:
THE FASCINATING NUMBERS ARE:
NIL
FREQUENCY OF FASCINATING NUMBERS IS: 0

Example 4:
INPUT:
m = 70
n = 450
OUTPUT:
INVALID INPUT

import java.util.Scanner;
class Fascinating{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("m = ");
        int m = Integer.parseInt(in.nextLine());
        System.out.print("n = ");
        int n = Integer.parseInt(in.nextLine());
        if(m > n || m < 100 || n < 100 || m > 9999 || n > 9999){
            System.out.println("INVALID INPUT");
            return;
        }
        int freq = 0;
        System.out.println("THE FASCINATING NUMBERS ARE:");
        for(int i = m; i <= n; i++){
            int j = i * 2;
            int k = i * 3;
            String num = i + "" + j + "" + k;
            if(digits(num) == 9){
                System.out.print(i + " ");
                freq++;
            }
        }
        if(freq == 0)
            System.out.print("NIL");
        System.out.print("\nFREQUENCY OF FASCINATING NUMBERS IS: " + freq);
    }
    public static int digits(String num){
        int count = 0;
        for(char i = '1'; i <= '9'; i++){
            int c = 0;
            for(int j = 0; j < num.length(); j++){
                if(i == num.charAt(j))
                    c++;
            }
            if(c == 1)
                count++;
        }
        return count;
    }
}

6 replies on “Fascinating Number in Java ISC Practical 2021”

100 and 180 are not Fascinating numbers because not all digits appear (0 to 9) after concatenation.

Sir,a program is given which states that:
WAP in JAVA to insert a new element after specific value in array.
Eg:
Enter the no. of elements to store: 10

Enter the elements of the array: 10 20 30 40 50 60 70 80 90 100

Before insertion, the array elements are 10 20 30 40 50 60 70 80 90 100

Enter the element after which you want to insert:100

Enter the element to insert:110

After insertion, the array elements are 10 20 30 40 50 60 70 80 90 100 110

Sir,a program is given which states that:”WAP in JAVA to insert a new element after specific value in an array.”
Eg:
Sample Input:
N=10
Enter array elements: 10 20 30 40 50 60 70 80 90 100
Before insertion : 10 20 30 40 50 60 70 80 90 100
Enter element to search after you want to insert: 100
Enter element to insert: 110
After insertion : 10 20 30 40 50 60 70 80 90 100 110

Ok let me solve it by myself………
hope everyone might find this comment as useful…..

import java.util.Scanner;
public class Fascinating_Num
{
long Num_Concatenate(int nn)
{
int n1,n2;long n3;String num,num1,num2,number;
n1=nn*2;
n2=nn*3;
num=String.valueOf(nn);
num1=String.valueOf(n1);
num2=String.valueOf(n2);
number=num+num1+num2;
n3=Long.valueOf(number);
return(n3);
}
int CheckFascinating(Long no)
{
Long no1=no;String no2;int c=0;Long d;no2=String.valueOf(no);int i,j;int tcount;
while(no1>0)
{
d=no1%10;
c++;
no1=no1/10;
}
int count =0;
for(i=49;i<=57;i++)
{
tcount=0;
for(j=0;j<c;j++)
{
if(no2.charAt(j)==(char)i)
{
tcount++;
}
}
if(tcount==1)
count++;
}
return(count);
}
public static void main (String args[])
{
Scanner in=new Scanner(System.in);
{
Fascinating_Num ob=new Fascinating_Num();int m,n;
System.out.println("Enter your numbers.First number should be less than second.");
m=in.nextInt();
n=in.nextInt();
int x;long y;int c1=0;int z;
if(m=10000)
{
System.out.println(“INVALID INPUT.”);
}
else
{
System.out.println(“THE FASCINATING NUMBERS ARE”);
for(x=m;x<=n;x++)
{
y=ob.Num_Concatenate(x);
z=ob. CheckFascinating(y);
if(z==9)
{
System.out.print(x+" ");
c1++;
}
}
System.out.println();
if(c1==0)
System.out.println("NULL");
System.out.println("THE FREQUENCY OF FASCINATING NUMBERS IS "+c1);
}
}
}
}
Thank you Happy Compiler to give me a chance to prove my intelligence

Sir,a program is given which states that:
WAP in JAVA to insert a new element after specific value in array.
Eg:
Enter the no. of elements to store: 10

Enter the elements of the array: 10 20 30 40 50 60 70 80 90 100

Before insertion, the array elements are 10 20 30 40 50 60 70 80 90 100

Enter the element after which you want to insert:100

Enter the element to insert:110

After insertion, the array elements are 10 20 30 40 50 60 70 80 90 100 110

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.