title: Transforming 4 sum problem from non-recursive to recursive function
body: <p>I need to  implement a Recursive Function (which
  accepts the Array and sum as parameters) to check if it contains four elements
  having the given sum.</p>
  <p>For Example:</p>
  <p>int[] intArray = {12, 18, 3, 2, 8, 2, 3, 5};</p>
  <p>sum = 35</p>
  <p>Output:
  Quadruplet exists.</p>
  <p>I created first non recursive function and then I tried to transform it to recursive function but it didn't work.</p>
  <p>Here is my non recursive function:</p>
  <pre><code>public class NonRecursive4Sum {
  
    void FourElementsSum (int arr[], int n, int X)
      {
          // In first step we save first number and search for other 3
          for (int i = 0; i &lt; n - 3; i++)
          {
              // Save 2. number and search for 2
              for (int j = i + 1; j &lt; n - 2; j++)
              {
                  // Save 3. and search for last one
                  for (int k = j + 1; k &lt; n - 1; k++)
                  {
                      // Here we save last number
                      for (int l = k + 1; l &lt; n; l++)
                      {
                          // This is the part I am trying to transform to recursive function
                          if (arr[i] + arr[j] + arr[k] + arr[l] == X){
                              System.out.print(&quot;Quadruplets exists&quot;);
                          }
                      }
                  }
              }
          }
      }
   
      
      public static void main(String[] args)
      {
          NonRecursive4Sum findfour = new NonRecursive4Sum ();
          int[] intArray= {12, 18, 3, 2, 8, 2, 3, 5};
         
          
          findfour.FourElementsSum(intArray, 8, 35);
      }
  }
  </code></pre>
  <p>This is modified if statement that I am trying to transform to recursive function:</p>
  <pre><code>if (arr[i] + arr[j] + arr[k] + arr[l] != X){
                              FourElementsSum ();
                          }
                          else if(arr[i] + arr[j] + arr[k] + arr[l] == X) {
                              System.out.println(&quot;Quadruplets Exist&quot;);
                          }
  </code></pre>