-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFascinating.java
42 lines (40 loc) · 1.02 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
import java.util.*;
class Fascinating
{
int n; //declaration
public Fascinating() //default constructor to initialise n
{
n=0;
}
void input() //input number
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number");
n=sc.nextInt();
}
void check()
{
int idx1,idx2,c=0; //declaration
String s;
int num2=n*2;
int num3=n*3;
s=""+n+num2+num3; //concatenating
for(char i='1';i<='9';i++)
{
idx1=s.indexOf(i);
idx2=s.lastIndexOf(i);
if(idx1==-1 || idx1!=idx2)
c=1;
}
if(c==1)
System.out.print("NUMBER IS NOT FASCINATING");
else
System.out.print(n+" is fascinating number"); //printing
}
public static void main()
{
Fascinating ob=new Fascinating(); //creating object ob
ob.input(); //calling function
ob.check(); //calling function
}
}