1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Monday's Programming Question

Monday September 22, 2008

No code to tinker with this week. This time you have to write the code from scratch. When I first started programming this was one of the tasks I was given. It's a simple exercise to get you thinking about logic, loops and variables.

The task it is to write a program that calculates and displays the first 22 numbers of a Fibonacci sequence. The sequence is the result of Fibonacci's attempt in 1202 to find out how many rabbits you get after a certain number of generations. Each number represents how many pairs of rabbits there would be when they are breeding under ideal circumstances. In a Fibonacci sequence each number is the sum of the previous two numbers (i.e., it starts with 0,1,1,2,3,5,8 and continues on).

Your code will display Fibonacci's hypothesis for 20 generations of rabbits (the first two numbers represent the start of the population and the maturing of the first pair of rabbits).

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.