Created
May 12, 2015 15:58
-
-
Save MrBean83/f05dd983c55dbb47451c to your computer and use it in GitHub Desktop.
Iterative Fibonacci Sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fibonacci { | |
public static void main(String args[]) { | |
// Declare variables | |
int index = 0, first = 0, second = 1; | |
System.out.println("Fibonacci Sequence"); | |
System.out.println(); | |
// Using a WHILE loop for this program. | |
while (index < 21) { | |
int next = first + second; | |
System.out.println("Fib " + index + " = " + second); | |
first = second; | |
second = next; | |
index++; | |
} // end while | |
} // end main | |
} // end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment