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.
As the pasted question says "each new number is the sum of the last two". So we see
I don't understand it
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.
Here's the main part of the code for you:
sum = sum + add;
add = sum-add;