Fibonacci series in java:

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:

  1. class FibonacciExample2{
  2. static int n1=0,n2=1,n3=0;
  3. static void printFibonacci(int count){
  4. if(count>0){
  5. n3 = n1 + n2;
  6. n1 = n2;
  7. n2 = n3;
  8. 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:

Leave a Comment