tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Articles > Java > Coding Examples > Fibonacci Series

Fibonacci Series 

Print Fibonacci Series.

File Name  :  
com/bethecoder/tutorials/coding/examples/FibonacciSeriesTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.coding.examples;

public class FibonacciSeriesTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    printFibonacciSeries(016);
    printFibonacciSeries(346);
    printFibonacciSeries(-246);
  }

  private static void printFibonacciSeries(int first, int second, int numOfElements) {
    System.out.print(first + "\t" + second);
    int next;
    for (int i = ; i < numOfElements ; i ++) {
      next = first + second;
      first = second;
      second = next;
      
      System.out.print("\t" + next);
    }
    System.out.println();
  }
}
   

It gives the following output,
0	1	1	2	3	5	8	13
3	4	7	11	18	29	47	76
-2	4	2	6	8	14	22	36


                    Print

   



Books Recommendation

 
 
bl  br