title: Recursive method If we call the program f(3)
body: <p>I have this code and i know that the answer is 6 but i do not know how we reached to that answer.</p>
  
  <p>i know that the steps of the program are as follows:</p>
  
  <p>f(3)</p>
  
  <p>2*f(4)</p>
  
  <p>1+f(2)</p>
  
  <p>1+f(1)</p>
  
  <p>Also how do we tell the recursive method to stop?</p>
  
  <pre><code>public static int f(int n) {        
      if (n &lt;= 1) return 1;           
  
      if (n % 2 == 0) return 1 + f(n / 2);  
  
      return 2 * f(n+1);
  </code></pre>
  
  <p>Expected  outcome is 6.</p>