Skip to content

Instantly share code, notes, and snippets.

@MrBean83
Created May 12, 2015 15:58
Show Gist options
  • Select an option

  • Save MrBean83/f05dd983c55dbb47451c to your computer and use it in GitHub Desktop.

Select an option

Save MrBean83/f05dd983c55dbb47451c to your computer and use it in GitHub Desktop.

Revisions

  1. MrBean83 created this gist May 12, 2015.
    18 changes: 18 additions & 0 deletions Fibonacci.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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