Advertisement
Guest User

Fibonacci Sequence

a guest
Oct 1st, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.30 KB | None | 0 0
  1. public class Sequence {
  2.    
  3.     public static long fib(int n) {
  4.         if (n < 2) {
  5.            return n;
  6.         }
  7.         else {
  8.             return fib(n-1)+fib(n-2);
  9.         }
  10.     }
  11.    
  12.     public static void main(String[] args) {
  13.         for (int i=0; i<=10; i++)
  14.             System.out.println(fib(i));
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement