MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / pow

Method pow

Lecture 29 - Recursion PS2/src/Power.java:7–14  ·  view source on GitHub ↗
(int p, int q)

Source from the content-addressed store, hash-verified

5// }
6
7 static int pow(int p, int q){
8 if(q == 0) return 1;
9 int smallPow = pow(p, q/2);
10 if(q % 2 == 0){ // even
11 return smallPow * smallPow;
12 }
13 return p * smallPow * smallPow;
14 }
15
16 public static void main(String[] args) {
17 System.out.println(pow(2, 5));

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected