We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent efbdc75 commit 20a36a0Copy full SHA for 20a36a0
Problem1Recursion.java
@@ -0,0 +1,29 @@
1
+// Calculate the power of a number using recursion
2
+
3
+package problem1.recursion;
4
5
+import java.util.*;
6
7
+public class Problem1Recursion {
8
9
+ public static void main(String[] args) {
10
11
+ Scanner input = new Scanner(System.in);
12
13
+ System.out.print("Enter a Number : ");
14
+ int n = input.nextInt();
15
16
+ System.out.print("Enter a Power : ");
17
+ int p = input.nextInt();
18
19
+ System.out.println(power(n, p));
20
+ }
21
22
+ static int power(int n, int p) {
23
+ if (p == 0) {
24
+ return 1;
25
+ } else {
26
+ return n * power(n, p - 1);
27
28
29
+}
0 commit comments