Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Assignment;
- public class Fibonacci
- {
- public static void main(String[] args)
- {
- // creating variables for the initial values of the sequence
- int a = 0 ;
- int b = 1 ;
- /* create a for loop that repeats 20 times in increments of 1,
- then define a new variable 'f' that is a sum of the initial sequence numbers.
- After that we basically redefine the variables so that the loop adds together
- previous number 'b' and the next (new number) 'f' */
- for (int i=0; i<=20; i++) {
- int f = a + b;
- a = b;
- b = f;
- System.out.println(f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement