Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public class FibonacciSequence {
- public static void main(String[] args) {
- // the fibonacci begins with 1, 1, and each subsequent number
- // is derived from the sum of the previous two
- long[] fibonacci= new long[20];
- fibonacci[0]=1;
- fibonacci[1]=1;
- for (int i=0;i<fibonacci.length-2;i++) {
- fibonacci[i+2]= fibonacci[i+1] + fibonacci[i];
- }
- for (long e: fibonacci)
- System.out.print(e+" ");
- }
- }
RAW Paste Data


