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 }

 

posted @ 2018-04-03 08:26  小粉要努力呀  阅读(93)  评论(0编辑  收藏  举报