Skip to content

Commit 50d2a35

Browse files
committed
Recursion programs added
1 parent 59ab3d1 commit 50d2a35

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

recursion/Lucky.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package recursion;
2+
3+
public class Lucky {
4+
boolean isLucky(int n){
5+
int counter = 2;
6+
if(counter > n) {
7+
return true;
8+
}
9+
if(n%counter == 0) {
10+
return false;
11+
}
12+
int np = n;
13+
np = np - np / counter;
14+
counter++;
15+
return isLucky(np);
16+
}
17+
public static void main(String[] args) {
18+
Lucky obj = new Lucky();
19+
System.out.println(obj.isLucky(13));
20+
}
21+
}

recursion/Phone.java

Whitespace-only changes.

recursion/test.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package recursion;
2+
public class test {
3+
public static String[] keypad = {".", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"};
4+
5+
public static void printComb(String str, int index, String combination) {
6+
if(index == str.length()) {
7+
System.out.print(combination + " ");
8+
return;
9+
}
10+
char currChar = str.charAt(index);
11+
String mapping = keypad[currChar - '0'];
12+
13+
for(int i=0; i<mapping.length(); i++) {
14+
printComb(str, index+1, combination + mapping.charAt(i));
15+
}
16+
}
17+
public static void main(String[] args) {
18+
String str = "23";
19+
printComb(str, 0, "");
20+
}
21+
}

0 commit comments

Comments
 (0)