Write a program to print Fibonacci series in java.
import java.util.Scanner;
class Fibo
{
public static void main(String args[])
{
int a=0,b=0,c=1,n,i;
Scanner s=new Scanner(System.in);
System.out.println("Enter the no");
n=s.nextInt();
System.out.println("Fibonacci series=");
for(i=0;i<=n-1;i++)
{
a=b;
b=c;
c=a+b;
System.out.println(a+"");
}
}
}
import java.util.Scanner;
class Fibo
{
public static void main(String args[])
{
int a=0,b=0,c=1,n,i;
Scanner s=new Scanner(System.in);
System.out.println("Enter the no");
n=s.nextInt();
System.out.println("Fibonacci series=");
for(i=0;i<=n-1;i++)
{
a=b;
b=c;
c=a+b;
System.out.println(a+"");
}
}
}
Output:
Comments
Post a Comment
If you have any query, please let us know