Skip to content

Commit 9c55572

Browse files
Refactor pow method to use Math.pow
1 parent 0c79d33 commit 9c55572

File tree

1 file changed

+1
-4
lines changed
  • src/main/java/com/thealgorithms/maths

1 file changed

+1
-4
lines changed

src/main/java/com/thealgorithms/maths/Pow.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ public static long pow(int a, int b) {
2727
if (b < 0) {
2828
throw new IllegalArgumentException("Exponent must be non-negative.");
2929
}
30-
long result = 1;
31-
for (int i = 1; i <= b; i++) {
32-
result *= a;
33-
}
30+
long result = (long) Math.pow(a , b);
3431
return result;
3532
}
3633
}

0 commit comments

Comments
 (0)