标题:递归求数组元素之和
取消只看楼主
gxl741852
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2010-6-29
结帖率:100%
 问题点数:0 回复次数:1 
递归求数组元素之和
public class Main {
public static void main(String[] args) {
   
int b=100;
int a[]=new int[10];
for(int i=0;i<10;i++)
{
 a[i]=i+1;System.out.print(a[i]+" ");
}
b=ff(a,100);
try{
System.out.print(b);
}catch (Exception e){
System.out.print(e);
}
}
public static int ff(int[] a,int c){

 if(c==0) return a[0];
 else return a[c]+ff(a,c-1);
}
}
搜索更多相关主题的帖子: 之和 递归 元素 
2010-08-03 18:58
gxl741852
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2010-6-29
得分:0 
知道了
2010-08-03 18:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-314742-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.541056 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved