Java Program to Find the Fibonacci series of a number
public class Sample {
public static int findFibbonacci(int fibbNum)
{
if(fibbNum==1 || fibbNum==2)
{
return 1;
}
int f1=1;int f2=1;int fib=1;
for(int i=3;i<=fibbNum;i++)
{
fib=f1+f2;
f1=f2;
f2=fib;
}
return fib;
}
public static void main(String args[])
{
for(int i=1;i<10;i++)
{
System.out.println(findFibbonacci(i));
}
}
}
No comments:
Post a Comment