Fascinating Numbers : Some numbers of 3 digits or more exhibit a very interesting property. The property is such that, when the number is multiplied by 2 and 3, and both these products are concatenated with the original number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes.
Some examples of fascinating Numbers are: 192, 219, 273, 327, 1902, 1920, 2019 etc.
import java.util.*;
class Str3
{
Scanner sc=new Scanner(System.in);
void main()
{
int a,b,i,n;
System.out.print("\nEnter any number: ");
n=sc.nextInt();
a=n*3;
b=n*2;
String s0=Integer.toString(n);
String s1=Integer.toString(a);
String s2=Integer.toString(b);
String s=s0+s1+s2;
if(s.length()!=9)
{
System.out.println("Not a fascinating no.");
System.exit(0);
}
int c[]=new int[10];
for(i=0;i<9;i++)
{
int ch=s.charAt(i);
int x=Character.getNumericValue(ch);
c[x]++;
}
for(i=1;i<9;i++)
{
if(c[i]!=1)
break;
}
if(i==9)
System.out.println("Fascinating no.");
else
System.out.println("Not a fascinating no.");
}
public static void main(String args[])
{
Str3 ob=new Str3();
ob.main();
}
}
Some examples of fascinating Numbers are: 192, 219, 273, 327, 1902, 1920, 2019 etc.
import java.util.*;
class Str3
{
Scanner sc=new Scanner(System.in);
void main()
{
int a,b,i,n;
System.out.print("\nEnter any number: ");
n=sc.nextInt();
a=n*3;
b=n*2;
String s0=Integer.toString(n);
String s1=Integer.toString(a);
String s2=Integer.toString(b);
String s=s0+s1+s2;
if(s.length()!=9)
{
System.out.println("Not a fascinating no.");
System.exit(0);
}
int c[]=new int[10];
for(i=0;i<9;i++)
{
int ch=s.charAt(i);
int x=Character.getNumericValue(ch);
c[x]++;
}
for(i=1;i<9;i++)
{
if(c[i]!=1)
break;
}
if(i==9)
System.out.println("Fascinating no.");
else
System.out.println("Not a fascinating no.");
}
public static void main(String args[])
{
Str3 ob=new Str3();
ob.main();
}
}
Other Programs On Numbers: CLICK HERE
No comments:
Post a Comment