11+ Java Programs to Print Fibonacci Series

This post contains a total of 11+ Java Program Examples with Source Code to Print Fibonacci Series. All these Fibonacci Series programs are made using Java.

You can use the source code of these examples with credits to the original owner.

Related Posts

Java Programs to Print Fibonacci Series

1. By Shubham Pandey

Made by Shubham Pandey. Program to Print Fibonacci Series of Number of Terms. Source

Enter number of terms : 10
Fibonacci series is
0 1 1 2 3 5 8 13 21 34 
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
        int n,a=0,b=1,c=0,t=1;
        System.out.println("Enter number of terms : ");
        n=(new Scanner(System.in)).nextInt();
        System.out.print("Fibonacci series is\n0 1 ");
        while(t<(n-1)){
            c=a+b;
            System.out.print(c+" ");
            a=b;
            b=c;
            t++;
        }
    }
}

2. By Vinayak Sharma

Made by Vinayak Sharma. A Simple Java Fibonacci Series Program. Source

3
5
8
13
21
34
55
89
144
233
public class Program
{
    public static void main(String[] args) {
    int n,s,l,u;
    l=1;u=2;n=0;
        
        while(n<10){ s=l+u;
        System.out.println(s);
        l=u;
        u=s;
        n++;
        }
    }
}

3. By Devbrath

Made by Devbrath. Program to print Fibonacci series from 0 to 50. Source

0 1 1 2 3 5 8 13 21 34		
public class Fibonacchi
{
// no need to print 0 or 1 before for loop
    public static void main(String[] args) {
        int a=1,b=0,c=0;
        for(int i=0; i<10;i++){
            b=a;
            a=c;
            c=a+b;
            System.out.print(a+"\t\t");
        }
    }
}

4. By Kishan Kumar Maharana

Made by Kishan Kumar Maharana. Zero to Infinity Fibonacci Series Program. Source

Enter a range:
0 1 1 2 3 5 8 13 21 34 55 89 ....
import java.util.*;
public class Program
{
	public static void main(String[] args) {
	int sum;
	int t1=0,t2=1;
	Scanner obj=new Scanner(System.in);
	System.out.println("Enter a range:");
	int n=obj.nextInt();
	for(int i=1;i<=n;++i)
	{
		System.out.print(t1+" ");
		sum=t1+t2;
		t1=t2;
		t2=sum;
	}
		
	}
}

5. By Deepak panwar

Made by deepak panwar. Source

0 1 1 2 3 5 8 13 21 34 55 89 144 233
public class Program
{
    public static void main(String[] args) {
   int i,a=0,b=1,c=0;
   System.out.print(a+" "+b);
   
   for(i=0;i<12;i++)
   {c=a+b;
   System.out.print(" "+c);
   a=b;
   b=c;}     
    }
}

6. By Rahul Agarwal

Made by Rahul Agarwal. Java Program to print Fibonacci Series using Recursion. Source

1
1
2
3
5
8
13
21
34
55
import java.io.*;
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int a=1;
        int b=1;
        System.out.println(a);
        System.out.println(b);
        int sum=0;
        for(int i=3;i<=n;i++){
            sum=a+b;
            System.out.println(sum);
            a=b;
            b=sum;
        }
    }
}

7. By Aashi Jaiswal

Made by Aashi Jaiswal. Program to Print Fibonacci series of String. Source

a,b,ba,bab,babba
import java.util.*;
public class Program
{
    String x , y, z;
    int n;
    Program(String a, String b, String ba)
    {
        x=a; y=b; z= y + "" + x;
    }
    void accept()
    {
        Scanner ma = new Scanner(System.in);
        // enter the no. of terms
        n = ma.nextInt();
    }
   void generate()
    {    
        int i;
        System.out.print(x +","+y );
        for(i=2; i<n; i++)
        {
          System.out.print(",");
           z = y + x ;
           System.out.print(z );
           x= y;
           y = z;
        }
    }
    public static void main(String[] args) 
    {
     Program FS = new Program("a","b" , "ba");  // change arguements as you like it
       FS.accept();
        FS.generate();
    }
}

8. By Kartikey Singh

Made by Kartikey Singh. Simple Fibonacci Series Program. The program needs number of terms you want in Fibonacci Series and see the output. Source

Fibonacci Series
Enter the Value of 'n' (Number of Terms): 10
Series is: 0 1 1 2 3 5 8 13 21 34
import java.util.*;
public class Program {
    public static void main(String[] args) {
           Scanner sc = new Scanner(System.in);
           int n = sc.nextInt(), a=0, b=1;
           System.out.print("Fibonacci Series" + "\nEnter the Value of 'n' (Number of Terms): " + n + "\nSeries is: ");      
           if(n == 0)       
              System.out.println("No Output!");     
           for(int i=1; i<=n/2; i++, a+=b, b+=a)          
              System.out.print(a + " " + b + " ");           
           if(n%2 != 0)      
              System.out.print(a);          
    }
}

9. By Roohi Mishra

Made by Roohi Mishra. Source

1
2
3
5
8
13
21
34
55
89
public class Program
{
    public static void main(String[] args) {
    int a,b,c,i;
    a=0;
    b=1;
    for(i=1;i<=10;i++)
    {
        c=a+b;
        System.out.println(c);
        a=b;
        b=c;
    }
        
    }
}

10. By Kondwani Mwafulilwa

Made by Kondwani Mwafulilwa. Fibonacci series program using for loop. Source

First 10 terms: 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 + 
public class Fibonacci {

    public static void main(String[] args) {

        int n = 10, t1 = 0, t2 = 1;
        System.out.print("First " + n + " terms: ");

        for (int i = 1; i <= n; ++i)
        {
            System.out.print(t1 + " + ");

            int sum = t1 + t2;
            t1 = t2;
            t2 = sum;
        }
    }
}

11. By Jenny Lance

Made by Jenny Lance. Basic Java Program to print Fibonacci Series. Source

The fibonacci series from 1 to 10 
0	1	

1			2			
3			5			
8			13			
21			34			
55			89
class Fibonacci
{
    public static void main(String[] args) 
	{
		long a = 0,b = 1,c = 0;

		System.out.println("The fibonacci series from 1 to 10 ");
		System.out.println("0	1	");
		
		for (int i = 0; i < 10; i++)
		{
			if(i%2==0) System.out.print("\n");

			c = a + b;
			a = b;
			b = c;
			System.out.print(b+"\t\t\t");
		}
	}
}

12. By Adhiraj Dhar

Made by Adhiraj Dhar. Source

The Fibonacci series is::
0
2
2
4
6
10
16
26
42
68
public class Fibonacci
{
    public static void main(String[] args) 
    {
       int a=0,b=2,c=0,n=3;
        System.out.println("The Fibonacci series is::");
        System.out.println(a);
        System.out.println(b);
        do{c=a+b;
        System.out.println(c);
        a=b;
        b=c;
        n=n+1;
        }
        while(n<=10);
    }
}