File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments