Hi there,
I wrote a VERY simply program attempting to use a recursive function to calculate a math problem and spit it out onto a table.
It prints once and then I'm getting a stack oveflow error on line 8 and then line 12:
package recurtable;
import java.text.*;
public class RecurTable {
static int D(int n)
{
if (n == 10 )
{
return 10;
}
return (D(n - 10) + n);
}
public static void main(String[] args) {
System.out.println("\n n\t D(n))\t D(n)/(n*n)");
for (int n = 20; n <= 250; n++)
{
int d_val = D(n);
DecimalFormat df = new DecimalFormat("#.####");
System.out.println(n + "\t" + d_val + "\t" +
df.format(d_val/(n*n)));
}
}
}
I'm new to recursion, so I'm unsure what's wrong with the function. Thanks guys!