Aqua Phoenix
     >>  Lectures >>  Java 1  
 

Navigator
   
 
       
   

1.18 Interactive Example - Tying Everything together

Compute the Fibonacci sequence of numbers, using an iterative approach.

public class Fibonacci {

  public static void main(String[] args) {

    int a = 0;
    int b = 1;
    int iterations = 0;

    System.out.print(a + " " + b);
    while (iterations < 30) {
      int temp = b;
      b = a + b;
      a = temp;
      System.out.print(" " + b);
      iterations++;
    }

    System.out.println();
  }
}