Java Program of Fibonacci series, Write a Java program for application for Fibonacci series
Program:-
class fibonacci
{
public static void main(String args[])
{
int no;
no = Integer.parseInt(args[0]);
Logic L=new Logic();
L.fibo(no);
}
}
class Logic
{
public void fibo(int n)
{
int a,b,c;
a=0;
b=1;
System.out.print(a +" ");
System.out.print(b +" ");
c=1;
do //Using Do....While Loop
{
c=a+b;
System.out.print(c +" ");
a=b;
b=c;
}while(c<n);
}
}
No comments:
Post a Comment