daily pastebin goal
30%
SHARE
TWEET

Fibonnaci

a guest Mar 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top