-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacsinatingNumber.java
81 lines (73 loc) · 1.23 KB
/
FacsinatingNumber.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
import java.util.Scanner;
public class FacsinatingNumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
long no=sc.nextLong();
if (isFacsinatingNo(no)&&isUnique(no))
System.out.println(no+" is a Facsinating Number");
else
System.out.println(no+" is a not Facsinating Number");
}
public static boolean isFacsinatingNo(long no){
long n1=no*2;
long n2=(no*3)*Power(no)+no;
n1=n1*Power(n2)+n2;
System.out.println(n1+" is a\n");
if (100000000<n1&&n1<999999999&&isUnique(n1)) {
return true;
}
else
return false;
}
public static int Power(long pow){
long ct=Count(pow);
int power=1;
while(ct>0){
power*=10;
ct--;
}
return power;
}
public static int Count(long no){
int ct=0;
if(no>0){
while(no>0){
ct++;
no/=10;
}
}
return ct;
}
public static boolean isUnique(long n)
{
int c=0;
int ct=Count(n);
while (n!=0)
{
long last=n%10;
long n1=n/10;
if (last!=0)
{
c++;
while (n1!=0)
{
long last1=n1%10;
if (last==last1)
{
return false;
}
else
n1=n1/10;
}
}
n=n/10;
}
if (c==ct)
return true;
else
return false;
}
}