title: Simple Divide and Conquer Example
body: <p>Here is my test divide and conquer program, but it gives me an error. I am heading in the right direction?</p>
  
  <pre><code>public class getSum {
      static int sum = 0;
      public static void main(String[] args) {
              int[] numbers = {2,2,2,2,2,2,2,2};
              int amount = 0;
             amount = sumArray(0,numbers.length,numbers);
             System.out.print(amount);
      }
  
      public static int sumArray(int first, int last, int[] A){
          int index = last - first;
          if(index == 1){
              return sum;
          }else if(index &lt;= 4 &amp;&amp; index &gt; 1){
              for(int i = first; first &lt; last; i++){
                  sum += A[i];
              }
              return sum;
          }
          return (sumArray(first, last / 2, A) + sumArray(last / 2, A.length, A));
      }
  }
  </code></pre>
  
  <p>Here is the error
  Exception in thread "main" java.lang.StackOverflowError
      at getSum.sumArray(getSum.java:16)</p>
  
  <p>I am looking for a simple example of taking an array of 16 and breaking it down to base case 4. I am having trouble completely understanding how to spit the array, then split it again. then combine all the splits in the end. </p>