# Fibonacci Series in Java Example

by Dinesh Thakur Category: Control Structures

Fibonacci series numbers are in the following Sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144..., The first two number in Fibonacci series are 0 and 1, and each subsequent next number is the sum of the previous two Numbers.

Algorithm for Fibonacci Series Numbers:-

step 1:Set a=0,b=1,c=0

step 3: Print a,b

step 4: Repeat through step-8 until (c < = size)

step 5: c=a+b

step 6: If (c < =size) then print c

step 7: Set a=b

step 8: Set b=c

step 9: Exit

Here is the Java Example for Fibonacci Series Numbers:

```import java.util.Scanner;

public class FibonacciSeries

{

public static void main(String args[])

{

int a=0,b=1,c=0,size;

Scanner s=new Scanner(System.in);

System.out.print("Enter a range : ");

size=s.nextInt();

System.out.print("\n");

System.out.print(a+","+b+",");

while(c<=size)

{

c=a+b;

if(c<=size)

System.out.print(c+",");

a=b;

b=c;

}

}

}

```  Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles