Skip to content

Commit a9b9f5f

Browse files
Merge pull request #211 from dineshparekh11/dinesh1
Fascinating Number or not
2 parents 5e7b34c + 6b20979 commit a9b9f5f

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Number Theory/Fascno.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//Find given number is Fascinating Number or not
2+
3+
import java.util.*;
4+
public class Fascno
5+
{
6+
public static void main(String args[])
7+
{
8+
int n1, n2, n3;
9+
Scanner sc=new Scanner(System.in);
10+
System.out.print("Enter any Number: ");
11+
n1 = sc.nextInt();
12+
n2 = n1 * 2;
13+
n3 = n1 * 3; //concatenating n1, n2, and n3 user input
14+
15+
String concatstr = n1 + "" + n2 + n3;
16+
boolean found = true;
17+
18+
for(char c = '1'; c <= '9'; c++) //checks all digits from 1 to 9 are present or not
19+
{
20+
int count = 0;
21+
22+
for(int i = 0; i < concatstr.length(); i++) //loop counts the frequency of each digit
23+
{
24+
char ch = concatstr.charAt(i);
25+
26+
if(ch == c)
27+
28+
count++;
29+
} //returns true if any of the condition returns true
30+
31+
if(count > 1 || count == 0)
32+
{
33+
found = false;
34+
break;
35+
}
36+
}
37+
if(found)
38+
System.out.println(n1 + " is a fascinating number.");
39+
else
40+
System.out.println(n1 + " is not a fascinating number.");
41+
}
42+
}
43+
44+
//by Dinesh

0 commit comments

Comments
 (0)