Skip to content

Commit d11b734

Browse files
using recursion
1 parent 56e8872 commit d11b734

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Maths/PowRecursion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public static void main(String[] args) {
1717
* @return the value {@code a}<sup>{@code b}</sup>.
1818
*/
1919
public static long pow(int a, int b) {
20-
int result = 1;
21-
for (int i = 1; i <= b; i++) {
22-
result *= a;
20+
if (b == 0) {
21+
return 1;
22+
} else {
23+
return a * pow(a, b - 1);
2324
}
24-
return result;
2525
}
2626
}

0 commit comments

Comments
 (0)