nikolas_serafini

Fibonacci - recursive

Oct 5th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. class Fibonacci {
  2.    
  3.     int calcFibo(double var) {
  4.         if (var == 0)
  5.             return 0;
  6.         else if (var == 1)
  7.             return 1;
  8.         else
  9.             return calcFibo(var - 1) + calcFibo(var - 2);
  10.     }
  11.  
  12.     public static void main(String[] args) {
  13.         Fibonacci fibo = new Fibonacci();
  14.         //Printing the first ten elements of the series
  15.         for (int i = 0; i < 10; i++) {
  16.             int series = fibo.calcFibo(i);
  17.             System.out.println(series);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment