Java program to find Fibonacci series of a given number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /*Write a program to find Fibonacci series of a given no. Example : Input - 8 Output - 1 1 2 3 5 8 13 21 */ class Fibonacci{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); //taking no. as command line argument. System.out.println("*****Fibonacci Series*****"); int f1, f2=0, f3=1; for(int i=1;i<=num;i++){ System.out.print(" "+f3+" "); f1 = f2; f2 = f3; f3 = f1 + f2; } } } |
public class Fibonacci {
public static void main(String[] args)
{
int n=10,i,f0=1,f1=1,f2=0;
if(f2==0 && f1==1)
{
System.out.println(f2);
System.out.println(f1);
}
for(i=0;i<=n;i++)
{
f2=f0+f1;
f0=f1;
f1=f2;
f2=f0;
System.out.println(f2);
}
}
}
It is but it is a bit wrong
After c=a+b; type if(c<n) break;
Then continue with the same code
another way
I’m having problem learning to code properly. I understand the concepts but I have a problem putting them in NetBeans
Here is the simple version of Fibonacci Series in Java http://goo.gl/JDZ8Xn
Output
plz give me output logic