Advertisement
therrontelford

Fibonacci sequence

Jan 29th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. public class FibonacciSequence {
  2.  
  3.     public static void main(String[] args) {
  4.         // the fibonacci begins with 1, 1, and each subsequent number
  5.         // is derived from the sum of the previous two
  6.        
  7.         long[] fibonacci= new long[20];
  8.         fibonacci[0]=1;
  9.         fibonacci[1]=1;
  10.        
  11.         for (int i=0;i<fibonacci.length-2;i++) {
  12.             fibonacci[i+2]= fibonacci[i+1] + fibonacci[i];
  13.         }
  14.        
  15.  
  16.     }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement