A to the power of B
1 public class Power{ 2 public long power(int a, int b){ 3 if (b == 0){ 4 return 1; 5 } 6 if (a == 0) { 7 return 0; 8 } 9 10 long half = power(a,b/2); 11 if(b % 2 == 1){ 12 return half * half * a; 13 } 14 return half * half; 15 } 16 }