# fibonacci number

http://crunchify.com/write-java-program-to-print-fibonacci-series-upto-n-number/

I have not understood what is fibonacci number and the logic to generate it using java program?

LVL 7
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
A  Fibonacci number is a number in the sequence defined by F[n]=F[n-1]+F[n-2] starting with F[0]=0, F[1]=1
each subsequent number is the sum of the previous two
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Ignore that triangle of numbers at the top with all the red lines. It is called Pascal's triangle and is very interesting to us math folks, but it adds nothing to the programming challenge.
0
Commented:
There's nothing magical in understanding Fibonacci numbers. We've probably all seen brainteasers where you're supposed to determine the next number in a sequence. If you were asked to do this given the series 0,1,1,2,3,5, wouldn't you expect the next number to be 8 (and the following number to be 13) given that the third number is the sum of the first two, the fourth the sum of the second two, the fifth the sum of the third two, the sixth the sum of the fourth two, etc. To generate them in Java is also a fairly simple routine using a loop or a recursionary function as has already been indicated. What is "magical" about Fibonacci numbers is how they exist so prevalently in nature. Things like the ratio of the spiral of a nautilus shell, the petals on flowers, and even the ratio of the lengths of the bones in your hand. There are anomalies, of course. Flowers and plants almost always have 1, 2, 3, 5, or 8 etc. petals or leaves. One of the reasons a four-leaf clover is so rare. No points please, I just wanted you to know why anyone cares about these numbers.
0
Software engineerCommented:
>> I have not understood what is fibonacci number
The article you point to is rather clear:
By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.
What do you not understand from the above two sentences?

>> the logic to generate it using java program?
I guess the program just takes the two previous numbers, makes the sum of those and moves on.
What do you not understand?
0
Commented:
fibonacciRecusion recursively applies the F[n]=F[n-1]+F[n-2] definition,
fibonacciLoop iteratively applies the each subsequent number is the sum of the previous two rule, (i.e. a dynamic programming optimization of the definition)
0
Author Commented:
now it is clear. I like below link better

http://java2novice.com/java-interview-programs/fibonacci-series/
``````
public class MyFibonacci {

public static void main(String a[]){

int febCount = 15;
int[] feb = new int[febCount];
feb[0] = 0;
feb[1] = 1;
for(int i=2; i < febCount; i++){
feb[i] = feb[i-1] + feb[i-2];
}

for(int i=0; i< febCount; i++){
System.out.print(feb[i] + " ");
}
}
}
``````

i got
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.