File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments