This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

1)The original problem that the Italian mathematician Leonardo Pisano Fibonacci investigated in the year 1202 was about how fast rabbits could breed in ideal circumstances. Suppose a newly-born pair of rabbits, one male, one female, are put in a field. Rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits. Suppose that our rabbits never die and that the female always produces one new pair (one male, one female) every month from the second month on. The puzzle that Fibonacci posed was...How many pairs will there be in one year? �At the end of the first month, they mate, but there is still one only 1 pair. �At the end of the second month the female produces a new pair, so now there are 2 pairs of rabbits in the field. �At the end of the third month, the original female produces a second pair, making 3 pairs in all in the field. �At the end of the fourth month, the original female has produced yet another new pair, the female born two months ago produces her first pair also, making 5 pairs, etc. a)Write a program that outputs the number of pairs of rabbits after 12 months. b)Now change your program so that it outputs the number of pairs of rabbits for any number of months specified by a user.

Now i have everything coded out, but is there a way in which i can take the value last calculated and add it together with the next value in the set.

As it is, 1, 1, 2, 3, 5, 8, 13. 1+1 = 2 2+3 = 5 and so on.

Any suggestions on how i can achieve this?

Stephen Foy - Microsoft Application Development Consultant

This looks like homework. You need to show us what you have coded so far; otherwise we might get the impression that you're tyring to get us to do your homewokr for you.

Originally posted by ste fing: ... Now i have everything coded out, but is there a way in which i can take the value last calculated and add it together with the next value in the set...

How do you have this coded now?

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org

Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143

posted

0

Got it. [ October 18, 2005: Message edited by: ste fing ]