mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 20:20:56 +08:00
using recursion
This commit is contained in:
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user