Skip to content

Commit f7e52b6

Browse files
Merge pull request PrajaktaSathe#142 from srijanishere/main
Check for Lucky Number in Java
2 parents a9a0b1b + 49afe26 commit f7e52b6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Programs/LuckyNumber.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//Program to check if the given number is a lucky number or not
2+
3+
import java.util.*;
4+
public class LuckyNumber
5+
{
6+
int c = 2;
7+
8+
//Method to check if the number is a Lucky Number
9+
public boolean checkLucky(int n)
10+
{
11+
if(c > n)
12+
return true;
13+
if(n % c == 0)
14+
return false;
15+
16+
//Position of the element
17+
n = n - (n/c);
18+
19+
//Incrementing the counter variable
20+
c++;
21+
return checkLucky(n);
22+
}
23+
24+
//Main method
25+
public static void main(String[] args)
26+
{
27+
Scanner sc = new Scanner(System.in);
28+
System.out.println("Enter the number to be checked : ");
29+
int a = sc.nextInt();
30+
LuckyNumber ob = new LuckyNumber();
31+
boolean res = ob.checkLucky(a);
32+
if(res == true)
33+
{
34+
System.out.println(a+" is a Lucky Number");
35+
}
36+
else
37+
{
38+
System.out.println(a+" is NOT a Lucky Number");
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)