Skip to content

Commit 197e96c

Browse files
authored
Update PowerOf2.java
1 parent 9e849a2 commit 197e96c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Recursion/PowerOf2/PowerOf2.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1+
import java.util.*;
12

3+
class PowerOf2 {
4+
5+
static int PowerOfTwo(int n){
6+
7+
if(n==0){
8+
return 1;
9+
}
10+
11+
int small_problem = PowerOfTwo(n-1);
12+
int big_problem = 2*PowerOfTwo(n-1);
13+
14+
return big_problem;
15+
}
16+
17+
public static void main(String[] args) {
18+
19+
Scanner scn = new Scanner(System.in);
20+
21+
int n = scn.nextInt();
22+
System.out.println("Two to the Power : " + n);
23+
24+
int ans = PowerOfTwo(n);
25+
26+
System.out.println("After Power Computation : " + ans);
27+
}
28+
}

0 commit comments

Comments
 (0)