title: Algorithm to calculate Fibonacci sequence implemented in Java gives weird result
body: <p>When I run Countdown.class I get the following output:</p>
  
  <pre><code>263845041
  -1236909152
  -973064111
  2084994033
  1111929922
  -1098043341
  13886581
  -1084156760
  -1070270179
  2140540357
  </code></pre>
  
  <p>Blast Off!</p>
  
  <p>The numbers before "Blast Off!" ought to be the first 10 Fibonacci numbers.  My source code is as follows.</p>
  
  <pre><code>    public class Fibonacci {
  
    public static long fib(int n) {
      if (n &lt;= 1) return 1;
      return fib(n-1) + fib(n-2);
    }
  
    public static long fastfib(int n) {
      int a = 0;
      int b = 1;
      int c = 0;
  
      for (int i = 0; i &lt;= n; n++) {
        c = a + b;
        a = b;
        b = c;    
      }
  
      return c;
    }
  
  }
  </code></pre>
  
  <p>and the class that implements the fastfib method is:</p>
  
  <pre><code>public class Countdown {
  
    public static void countdown(int n) {
      if (n == 0) System.out.println("Blast Off!");
      else {
        System.out.println(Fibonacci.fastfib(n));
        countdown(n - 1); 
      }
    }
  
    public static void main(String[] args) {
      countdown(10);
    }
  }
  </code></pre>