A Fibonacci Series in Java is a series of numbers in which the next number is the sum of the previous two numbers. The first two numbers of the Fibonacci series are 0 and 1.
Example:
//0+1=1
//1+1=2
//1+2=3
//2+3=5
//3+5=8
//5+8=13
//8+13=21
//13+21=34
//21+34=55
//34+55=89
Example:
- class FibonacciExample2{
- static int n1=0,n2=1,n3=0;
- static void printFibonacci(int count){
- if(count>0){
- n3 = n1 + n2;
- n1 = n2;
- n2 = n3;
- System.out.print(” “+n3);
Example program:
public class Finociseries
{
public static void main(String[] args)
{
int f =0, s = 1;
int t = f + s;
while(t<100)
{
System.out.print( t+ " " ); //1
f = s; //f = 1
s = t; //s = 1
t = f + s;
}
}
}
output:
