Java program to print a Fibonacci series

      No Comments on Java program to print a Fibonacci series
import java.util.Scanner;
class scan
{ 
  public static void main(String arg[])
	{
		  int z,i,n,x=0,y=1;
  Scanner kb=new Scanner(System.in);
  System.out.println("Enter Number of digit you want to print fibonacci series");
  z=kb.nextInt();
 System.out.println("Fibonacci series is:- ");
 for(i=0;i<=z;i++)
 {
	System.out.print(" "+x);
	 n=x+y;
	 x=y;
	 y=n;
 }
	}
	
}

OUTPUT:-

Leave a Reply

Your email address will not be published. Required fields are marked *