# Help with Java

• 01-09-2010, 10:43 PM
Lebron23
Help with Java
Write a program that lets you enter a number n and that calculates the nth Fibonacci number: 1,1,2,3,5,8,... Each new number is the sum of the last two.

Please help me with this on Ready to program Java. I don't understand it so if anyone can help me with it.

Thanks
• 01-09-2010, 11:04 PM
pbrockway2
Quote:

I don't understand it
As the pasted question says "each new number is the sum of the last two". So we see

2=1+1
3=2+1
5=3+2
8=5+3

What you think the next few terms of the sequence might be?

In fact the first step in figuring out how to "write a program that..." is often to try and do the task without a computer so that you can see for yourself what the steps are. So what is the 15th term of the Fibonacci sequence?

Think in detail about the steps you carried out. How many "terms" did you have to keep track of as you figured out the 15th term?

Once you have a clear idea of the actual steps that have to be carried out you will be in a position to start writing code. And if you get stuck you will have a specific point that you are stuck with: a specific question to ask.
• 01-10-2010, 05:36 AM
Draugnar
Here's the main part of the code for you:

Code:

``` sum = sum + add; add = sum-add;```