Fibonacci

 
public class Main {
  public static void main(String[] args) {
    int n0 = 1, n1 = 1, n2; // Initialize variables
    System.out.print(n0 + " " + // Print first and second terms
        n1 + " "); // of the series

    for (int i = 0; i < 18; i++) { // Loop for the next 18 terms
      n2 = n1 + n0; // Next term is sum of previous two
      System.out.print(n2 + " "); // Print it out
      n0 = n1; // First previous becomes 2nd previous
      n1 = n2; // And current number becomes previous
    }
    System.out.println(); // Terminate the line
  }
}
  

Output:


1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
Home 
  Java Book 
    Runnable examples  

Algorithm:
  1. Binary search
  2. Binary Search Insert
  3. Recursive Binary Search Implementation in Java
  4. Linear Searching double Arrays
  5. Bubble sort
  6. Heap sort
  7. Merge sort
  8. Fast Merge Sort
  9. Fast Quick Sort
  10. Simple version of quick sort
  11. Quicksort for sorting arrays
  12. Quick Sort Implementation with median-of-three partitioning and cutoff for small arrays
  13. Quick sort with median-of-three partitioning
  14. Insert sort
  15. Insert Sort for objects
  16. Selection sort
  17. Shell sort
  18. Fibonacci
  19. Hanoi puzzle
  20. Table of fahrenheit and celsius temperatures
  21. Growable integer array
  22. Linked List class
  23. Binary Tree
  24. Tree with generic user object