MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / LuckyNumber

Class LuckyNumber

Programs/LuckyNumber.java:4–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3import java.util.*;
4public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected