1. Member Join Date
Jan 2010
Posts
1
Rep Power
0

## 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.

Thanks  Reply With Quote

2. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## 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.  Reply With Quote

3. Member Join Date
Jan 2010
Posts
4
Rep Power
0

## Here's the main part of the code for you:

Java Code:
```sum = sum + add;  Reply With Quote