forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spy_Recur.java
38 lines (35 loc) · 800 Bytes
/
Spy_Recur.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
import java.util.*;
class Spy_Recur
{
int spy(int n,int s,int p)
{
int c=0;
if(n==0)
{
if(s==p)
return 1;
return 0;
}
else
{
c=n%10;
s=s+c;
p=p*c;
n=n/10;
return spy(n,s,p);
}
}
public static void main()
{
Scanner sc=new Scanner(System.in);
Spy_Recur ob=new Spy_Recur();
int no,p;
System.out.println("Enter a no.");
no=sc.nextInt();
p=ob.spy(no,0,1);
if(p==1)
System.out.print("Spy no.");
else
System.out.print("Not Spy");
}
}