title: Recursion to get all variants sum in array
body: <p>I am trying to write a recursive method that allows me to sum all the possible variants of integers in an array. </p>
  
  <p>Eg. For an array with the following values [1, 2, 3, 4]</p>
  
  <p>Results: [1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2, 4], [3, 1], [3, 2], [3, 4], [4, 1], [4, 2], [4, 3], [1, 2, 3], [1, 2, 4], [2, 1, 3], [2, 1, 4] etc etc.. </p>
  
  <p>I am totally new to recursion. What I understood was to divide the problem into a smaller one. But I can't seem  to see it for this case. Can someone help me out here?</p>
  
  <p>EDIT:</p>
  
  <pre><code>class Stick {
  
      public int sum(ArrayList&lt;Integer&gt; array) { 
          int total = 0;
          for(int i = 0; i &lt; array.size(); i++) {
              total += array.get(i);
          }
  
          return total;
      }
  
      public void permute(ArrayList&lt;Integer&gt; in, ArrayList&lt;Integer&gt; out) {
          if(out.size() &gt; 0) { print(out); System.out.println(sum(out)); }
  
          for(int i = 0; i &lt; in.size(); i++) { 
              int item = in.get(i);
              in.remove(i);
              out.add(item);
              permute(in , out);
          }
      }
  
      public void print(ArrayList&lt;Integer&gt; integer) {
          System.out.print("[");
          for(int i = 0; i &lt; integer.size(); i++) {
              System.out.print(integer.get(i) + ", ");
          }
          System.out.print("]");
      }
      public static void main(String[] args) {
          ArrayList&lt;Integer&gt; in = new ArrayList&lt;Integer&gt;();
          ArrayList&lt;Integer&gt; out = new ArrayList&lt;Integer&gt;();
          in.add(1); in.add(2); in.add(3); in.add(4);
  
          Stick stick = new Stick();
          stick.permute(in, out);
      }
  }
  </code></pre>