java计算编程x^n(x的n次方)的递归方法

[复制链接]
查看11 | 回复5 | 2013-4-1 17:14:03 | 显示全部楼层 |阅读模式
public static void main(String[] args) {System.out.println(jiecheng(5,3));}public static int jiecheng(int x,int y){
if(y>0)
return x*jiecheng(x,y-1);
return 1;}没什么好不好的,就是计算次方,如上。...
回复

使用道具 举报

千问 | 2013-4-1 17:14:03 | 显示全部楼层
public int function(int x,int n){if(n=0) return 1;else return x*function(x,n-1);}哪里不懂的就问吧...
回复

使用道具 举报

千问 | 2013-4-1 17:14:03 | 显示全部楼层
貌似java里有求n次方的方法,如java.math里的,找找吧...
回复

使用道具 举报

千问 | 2013-4-1 17:14:03 | 显示全部楼层
class Recursion { public long power(int x, int n) { if(1==n){ return x; }else{ return x*power(x, n-1); } } public static void main(String[] args) { Recurs...
回复

使用道具 举报

千问 | 2013-4-1 17:14:03 | 显示全部楼层
public int testDg(int x,int n) {if (n == 1) return x;return x * testDg(x,n-1); }...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行