daily pastebin goal
41%
SHARE
TWEET

Fibonacci sequence

therrontelford Jan 29th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class FibonacciSequence {
  3.  
  4.     public static void main(String[] args) {
  5.         // the fibonacci begins with 1, 1, and each subsequent number
  6.         // is derived from the sum of the previous two
  7.        
  8.         long[] fibonacci= new long[20];
  9.         fibonacci[0]=1;
  10.         fibonacci[1]=1;
  11.        
  12.         for (int i=0;i<fibonacci.length-2;i++) {
  13.             fibonacci[i+2]= fibonacci[i+1] + fibonacci[i];
  14.         }
  15.         for (long e: fibonacci)
  16.             System.out.print(e+" ");
  17.  
  18.     }
  19.  
  20. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top