forked from kushrajpurohit18/Hacktoberfest-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fascinating.java
89 lines (85 loc) · 1.93 KB
/
Fascinating.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Fascinating Number: When a number( 3 digits or more ) is multiplied by 2 and 3, and when both these products
are concatenated with the original number, then it results in all digits from 1 to 9 present exactly once
*/
package com.company;
import java.util.*;
public class Fascinating
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Input m & n");
int m=sc.nextInt();
int n=sc.nextInt();
int a,b,c;
String s="",f=" ",a1,b1,c1;
int freq=0;
for(int i=m;i<n;i++)
{
a=i*1;
a1=a+"";
b=i*2;
b1=b+"";
c=i*3;
c1=c+"";
s=a1+""+b1+""+c1;
if(fascinate(s))
{
f+=i+" ";
freq++;
}
else
continue;
}
if(freq==0)
{
System.out.println("No Fascinating Number");
}
else
{
System.out.println("Fascinating Numbers:"+f);
System.out.println("Frequency Of Fascinating Numbers:"+freq);
}
}
static boolean fascinate(String s)
{
String s1="";
String n="";
char ch;
for(int i=0;i<s.length();i++)
{
ch=s.charAt(i);
if(ch=='0')
continue;
else
{
s1+=ch;
}
}
if(s1.length()==9)
{
for(int i=1;i<=9;i++)
{
n=i+"";
if(s1.indexOf(n)==s1.lastIndexOf(n))
{
continue;
}
else
return false;
}
return true;
}
else
return false;
}
}
/*
Example:-
Input m & n
100
500
Fascinating Numbers: 192 219 273 327
Frequency Of Fascinating Numbers:4
*/