using recursion

This commit is contained in:
shellhub 2019-10-24 11:54:37 +08:00
parent 56e887213b
commit d11b7347b6

View File

@ -17,10 +17,10 @@ public class PowRecursion {
* @return the value {@code a}<sup>{@code b}</sup>.
*/
public static long pow(int a, int b) {
int result = 1;
for (int i = 1; i <= b; i++) {
result *= a;
}
return result;
if (b == 0) {
return 1;
} else {
return a * pow(a, b - 1);
}
}
}