title: How should I increment numbers using recursion?
body: <p>I have a problem with numbers that I want to increment using a recursive function.  The function didn't return the value as I was expecting.  Upon debugging I saw the numbers being increased but when the value is returned, it appears that the adjustments to the numbers are returned in reverse order.</p>
  
  <p>Here is a simple example:</p>
  
  <pre><code>private static int recursionTest(int num){
      if (num &lt; 10){
          recursionTest(++num);
      }
      return num;
  }
  
  public static void main(String[] args) {
      System.out.println(recursionTest(1));
  }
  </code></pre>
  
  <p>The output is always 2.  When I'm using the step-through debugger I see the following:</p>
  
  <ol>
  <li>The number increases by 1 with each iteration.</li>
  <li>When the number reaches 10 the return statement is executed.</li>
  <li>The debugger then highlights the "recursionTest(++num);" line but the number is decreased by 1.</li>
  <li>The return statement is executed again.</li>
  <li>Steps 3 and 4 is repeated until a value of 2 is finally returned.</li>
  </ol>
  
  <p>Why is the value being decremented in the end, and how do I return the initially calculated value? </p>