Results 1 to 3 of 3

Thread: Help with Java

  1. #1
    Lebron23 is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  3. #3
    Draugnar is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default

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

    Java Code:
    sum = sum + add;
    add = sum-add;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •