Guys try this logic for Fascinating Number; I've broken down the program into bits so that it'll be easier to comprehend. Its done using Strings,Arrays,Sorting and checking...
import java.util.*;
class Fascinating
{
public static void main()
{
//accepting
System.out.println("Enter Number: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String temp=Integer.toString(n*1)+Integer.toString(n*2)+Integer.toString(n*3);
int[]a={1,2,3,4,5,6,7,8,9};
char[]ch=temp.toCharArray();
//sorting
for(int i=0;i<ch.length-1;i++)
{
for(int j=0;j<ch.length-i-1;j++)
{
if(ch[j]>ch[j+1])
{
char aa=ch[j];
ch[j]=ch[j+1];
ch[j+1]=aa;
}
}
}
//counting
boolean b=false;
int count=0;
for(int i=0;i<ch.length;i++)
{
if(ch[i]==0)
continue;
else
{
if(((int)ch[i]-48)==a[i]){
b=true;
count++;
}
else
b=false;
}
}
//printing
if(b==true&&count==9)
System.out.println("Fascinating Number!");
else
System.out.println("Not Fascinating Number!");
}
} |
|
| asked by Rochan HM (rochana_hm3) 9 years ago | |
2 | |
Other Questions on This Topic
Chhod aaye the kinara kabhi apni talash mein, Par dil ki gehrayi se ek aisi aawaz aayi, Ki lautna pada hamein isi mod ki talash mein. |
|
| asked by Nisarg Bhavsar (nisarg71) 122 days ago | |
2 | |
Bengali grammar icse question paper can I get? |
|
| asked by Debosmita Malik (debosmitamalik) 176 days ago | |
1 | |
I wish to download question papers for ICSE prelims and I cannot do that. Can you provide the details of the Customer support for Respaper to get in touch with regarding the issue mentioned above. |
|
| asked by S.Hemalata Rajaram (hema1877) 280 days ago | |
1 | |

