forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfascinating.java
More file actions
37 lines (37 loc) · 849 Bytes
/
fascinating.java
File metadata and controls
37 lines (37 loc) · 849 Bytes
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
import java.io.*;
class Fascinating_2021
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the value upto which you have to find fascinating number: ");
int size = Integer.parseInt(br.readLine());
System.out.println("Fascinating numbers are:");
for (int i = 1; i <= size; i++)
{
if (isFascinate(i))
System.out.print(i + " ");
}
}
static boolean isFascinate(int n1)
{
int n2=n1*2;
int n3=n1*3;
String s1=n1+Integer.toString(n2)+Integer.toString(n3);
int []a={0,0,0,0,0,0,0,0,0,0};
for(int i=0;i<s1.length();i++)
{
a[s1.charAt(i)-48]++;
}
int flag=0;
for(int i=1;i<a.length;i++)
{
if(a[i]!=1)
{
flag=1;
break;
}
}
return flag == 0;
}
}