Advertisement
Glenpl

Untitled

Jun 14th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1.  
  2. public class Fibonacci {
  3.  
  4.     public static void main(String[] args) {
  5.        
  6.         for(int i = 0; i < 15; i++)
  7.             System.out.println( fib( i ) );
  8.     }
  9.    
  10.     private static long fib(int index) {
  11.        
  12.         long x = 0, y = 1;
  13.        
  14.         for(int i = 0; i < index; i++) {
  15.             if (x > y) y += x;
  16.             else x += y;
  17.         }
  18.        
  19.         return Math.min(x, y);
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement