Hello everyone! I have just started working with java (my first programming language) and I am having some difficulties. I am trying to create a program that will generate the first 20 numbers of the fibonacci series but my code will not work. I have listed it below:

I remember implementing a fibonachi sequence (spellling?) when I first started programming but have no idea what it is now so maybe giving an explanation of what a fibo sequence is will help you get more help here, I personally cannot be bothered researching....

11-13-2010, 01:56 AM

pbrockway2

Quote:

but my code will not work.

THis doesn't tell us anything. What runtime behaviour do you observe when you run this code? And what behaviour did you expect to see?

-----

If I were you I would forget the DynamicArrayofInt and just use a List: that's what they are meant for.

11-13-2010, 02:17 AM

al_Marshy_1981

yup exactly what pbrockway2 has said and myself...

1st. do describe what a fibonachi sequence is and
2nd please do be specific what part of your program is not working

Your help will be much faster coming if you do so...

11-13-2010, 04:17 AM

Singing Boyo

I think marshy is a bit annoyed today :p

Anyway, fibonacci sequence is {1,1,2,3,5,8,13,21,34,55,89,<end excessive mental math>}. Basically, the next number is the sum of the previous two numbers, always starting with 1.

@OP:start by incrementing/decrementing your variables. You'll probably also want to switch to a List or even a fixed-size array with a size of 20, instead of your 'DynamicArrayOfInt' class. Besides this, we need you to offer more about what you expect, and what you get, which is what pbrockway said. We're here because we're nice people, not because it pays well, so we try to refrain from tiring our brains figuring out someone else's code.

11-13-2010, 09:45 AM

m00nchile

Also, have you learned about recursion yet? Defining the fibo sequence recursively is a very simple task.

11-13-2010, 01:02 PM

venerik

Since you are completely new to programming here are some improvements for your code. They do not solve your Fibonacci problem but make you a better coder in the long run. The orange parts is your original code, the green parts are my improvements.