title: how to run recursive function in Java
body: <p>I am trying to learn Dynamic Programming and one of the examples they give in <a href="http://en.wikipedia.org/wiki/Dynamic_programming" rel="nofollow">Wikipedia</a> of what is not Dynamic Programming, is a recursive way of getting Fibonacci sequence up to certain number. I.E. </p>
  
  <p>Given a recursive function, say:</p>
  
  <pre><code>fib(n) = 0 if n = 0
           1 if n = 1
           fib(n - 1) + fib(n - 2) if n &gt;= 2
  </code></pre>
  
  <p>We can easily write this recursively from its mathematic form as:</p>
  
  <pre><code>function fib(n)
    if(n == 0 || n == 1)
      n
    else
      fib(n-1) + fib(n-2)
  </code></pre>
  
  <p>But I cannot get the pseudo code to work. </p>
  
  <p>when I do this method in Java, I get an error <em>the operator + is undefined for methods void</em>:</p>
  
  <pre><code> public void fib(int n) {
  
       if (n == 0 || n == 1) {
  
           System.out.println(n);
       } else
           return fib(n - 1) + fib(n - 2);
  
   }
  </code></pre>