Fascinating Number is a number which when multiplied by 2 and 3 the products concatenated with original number contains digits from 1-9 exactly once.
Example 1: 192. 192*2 = 384 and 192*3 = 576. “192”+”384″+”576″ = 192384576 contains digits from 1-9 exactly once. Hence it is a Fascinating Number.
Example 2: 181. 181*2 = 362 and 181*3 = 543. “181”+”362″+”543″ = 181362543 contains repetition of digits and missing digits. Hence it is not a Fascinating Number.
Java
import java.util.*;
public class FascinatingNumber
{
public static void main(String args[])
{
int n=0,r=0,f=0,concat=0,copy=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
concat=Integer.valueOf(""+n+(n*2)+(n*3));
copy=concat;
for(int i=1;i<=9;i++,f=0,concat=copy)
{
while(concat>0)
{
r=concat%10;
if(i==r)
{
f++;
}
concat=concat/10;
}
if(f!=1)
{
System.out.println(n+" is not a Fascinating Number");
System.exit(1);
}
}
System.out.println(n+" is a Fascinating Number");
}
}Java