【发布时间】:2013-11-22 17:41:32
【问题描述】:
这是我的代码:
public int sum(int[] array, int index)
{
//int index is the number of elements in the array.
//Here is my base case:
if (index == 0)
return 0;
//Now it's time for the recursion
else
return array[index] + sum(array, index + 1);
}
我不断收到越界错误,但我没有做错什么。
【问题讨论】:
-
您的停止条件在哪里?你没有一个,你一直在增加索引。