forked from Mystery-2-Dev/Java_Algorithms-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlucky.java
More file actions
33 lines (24 loc) · 692 Bytes
/
Copy pathlucky.java
File metadata and controls
33 lines (24 loc) · 692 Bytes
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
import java.io.*;
class lucky
{
public static int counter = 2;
static boolean isLucky(int n)
{
int next_position = n;
if(counter > n)
return true;
if(n%counter == 0)
return false;
next_position -= next_position/counter;
counter++;
return isLucky(next_position);
}
public static void main (String[] args)
{
int x = 5;
if( isLucky(x) )
System.out.println(x+" is a lucky no.");
else
System.out.println(x+" is not a lucky no.");
}
}