# Recursion Stackoverflow Error help!

• July 28th, 2012, 10:50 AM
Peopshu
Recursion Stackoverflow Error help!
Code Java:

```public class Project02 { private double areaTotal; public Project02(double Total) { areaTotal = Total; } public static double TotalArea(double areaTotal) { double []x = {7.5774, 6.4226, 4.3453, 3.4226, 4.5724, 6.6547}; double []y = {4.6340, 6.3660, 6.2321, 4.3660, 2.6340, 2.7679};   double a1 = (x[0] * y[1] + x[1] * y[2] + x[2] * y[0] - y[0] * x[1] - y[1] * x[2] - y[2] * x[0])/2; double a2 = (x[0] * y[2] + x[2] * y[3] + x[3] * y[0] - y[0] * x[2] - y[2] * x[3] - y[3] * x[0])/2; double a3 = (x[0] * y[3] + x[3] * y[4] + x[4] * y[0] - y[0] * x[3] - y[3] * x[4] - y[4] * x[0])/2; double a4 = (x[0] * y[4] + x[4] * y[5] + x[5] * y[0] - y[0] * x[4] - y[4] * x[5] - y[5] * x[0])/2;   double []a = {a1, a2, a3, a4};   double result; if(areaTotal == 0 && areaTotal > 3) { result = 0; System.out.println("Done"); } else { result = a[(int)areaTotal] + TotalArea(a[(int)areaTotal - 1]); System.out.println(result); } return result; } }```

DRIVER
Code Java:

```import java.util.Scanner;   public class Project02Driver { public static void main(String []args) { int areaTotal; Scanner scan = new Scanner(System.in); areaTotal = scan.nextInt(); System.out.println(Project02.TotalArea(areaTotal)); } }```

I run this program using the driver class. However, every time I input a number for areaTotal I get a stackoverflow error. My end goal in this program is to be able to use recursion to successfully print the total in array a using my driver program.
• July 28th, 2012, 11:25 AM
elamre
Re: Recursion Stackoverflow Error help!
Not sure if it's the problem, but i found something suspicious. Look at the following statement. What are you trying to achieve here?
Code java:

` if(areaTotal == 0 && areaTotal > 3)`
When would this return true and when would this return false? :)