Home | Tutorials | Articles | Videos | Products | Tools | Search
 Interviews | 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  : [email protected]

 ``` package com.bethecoder.tutorials.coding.examples; public class FibonacciSeriesTest {   /**    * @param args    */   public static void main(String[] args) {     printFibonacciSeries(0, 1, 6);     printFibonacciSeries(3, 4, 6);     printFibonacciSeries(-2, 4, 6);   }   private static void printFibonacciSeries(int first, int second, int numOfElements) {     System.out.print(first + "\t" + second);     int next;     for (int i = 0 ; 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
```