title: Java Recursion: Example
body: <p>I am aware of how <a href="https://en.wikipedia.org/wiki/Recursion_(computer_science)" rel="nofollow noreferrer">recursion</a> works, i.e:</p>
  
  <p><code>method calls itself until it reaches a base case then it can start solving its problem.</code></p>
  
  <p>In this code example is a method or removing flowers from a vase. </p>
  
  <p>I have added a trace statement to be able to see how many flowers are in the vase after every call. However the output leaves 7 flowers in the vase. I am confused as to why?</p>
  
  <p>Code:</p>
  
  <pre><code>public static void emptyVase( int flowersInVase ) {
      if( flowersInVase &gt; 0 ) {
      // take one flower and
          emptyVase( flowersInVase - 1 ) ;
  
          System.out.println(flowersInVase);
  
  
      } else {
             // the vase is empty, nothing to do
  
      }
  }
  </code></pre>
  
  <p>Invoking the method:</p>
  
  <pre><code>public class RecursionPractice {
  
      public static void main(String[] args) {
  
          emptyVase(7);    
      }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1
  2
  3
  4
  5
  6
  7
  </code></pre>