标题:改进的求x的n次方 public class TestXNPow { public int hh(int x,int n) { if(n==1) { return x; }else if(n==2) { return x*x; }else { return hh(x,2)*hh(x,n-2); } } @Test public void test() { int x=2; int n=5; int hh = this.hh(x, n); System.out.println("hh:"+hh); } public int hh02(int x,int n) { if(n==1) { return x; }else if(n==2) { return x*x; }else { if(n%2==0) { return hh(hh(x,n/2),2); }else { return hh(x,n/2)*hh(x,n/2+1); } } } @Test public void test02() { int x=2; int n=10; int hh02 = this.hh02(x, n); System.out.println("hh02:"+hh02); } }