Advertisement
Guest User

Fibonnaci

a guest
Mar 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. package Assignment;
  2.  
  3. public class Fibonacci
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. // creating variables for the initial values of the sequence   
  9.     int a = 0 ;
  10.     int b = 1 ;
  11.  
  12.         /* create a for loop that repeats 20 times in increments of 1,
  13.          then define a new variable 'f' that is a sum of the initial sequence numbers.
  14.         After that we basically redefine the variables so that the loop adds together
  15.         previous number 'b' and the next (new number) 'f' */
  16.    
  17.         for (int i=0; i<=20; i++) {
  18.         int f = a + b;
  19.         a = b;
  20.         b = f;
  21.         System.out.println(f);
  22.         }
  23.  
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement