using recursion
This commit is contained in:
parent
56e887213b
commit
d11b7347b6
@ -17,10 +17,10 @@ public class PowRecursion {
|
|||||||
* @return the value {@code a}<sup>{@code b}</sup>.
|
* @return the value {@code a}<sup>{@code b}</sup>.
|
||||||
*/
|
*/
|
||||||
public static long pow(int a, int b) {
|
public static long pow(int a, int b) {
|
||||||
int result = 1;
|
if (b == 0) {
|
||||||
for (int i = 1; i <= b; i++) {
|
return 1;
|
||||||
result *= a;
|
} else {
|
||||||
|
return a * pow(a, b - 1);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user