Skip to content

Instantly share code, notes, and snippets.

@MrBean83
Created May 12, 2015 15:58
Show Gist options
  • Save MrBean83/f05dd983c55dbb47451c to your computer and use it in GitHub Desktop.
Save MrBean83/f05dd983c55dbb47451c to your computer and use it in GitHub Desktop.
Iterative Fibonacci Sequence
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