MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / pow

Method pow

src/main/java/com/thealgorithms/maths/Pow.java:26–35  ·  view source on GitHub ↗

Computes the value of the base raised to the power of the exponent. The method calculates a b by iteratively multiplying the base a with itself b times. If the exponent b is negative, an IllegalArgumentException is thrown. @param a

(int a, int b)

Source from the content-addressed store, hash-verified

24 * @throws IllegalArgumentException if {@code b} is negative.
25 */
26 public static long pow(int a, int b) {
27 if (b < 0) {
28 throw new IllegalArgumentException("Exponent must be non-negative.");
29 }
30 long result = 1;
31 for (int i = 1; i <= b; i++) {
32 result *= a;
33 }
34 return result;
35 }
36}

Callers 15

testPowMethod · 0.95
testPowHandlesOneBaseMethod · 0.95
getRandomScoresMethod · 0.45
piMethod · 0.45
updateMethod · 0.45
mainMethod · 0.45
haversineMethod · 0.45

Calls

no outgoing calls