## Fibonacci NumbersAs far as we know, the Fibonacci series was first discovered by Leonardo of Pisa about 1200 C.E. Leonardo was trying to answer the question, " Quot paria coniculorum in uno anno ex uno pario germinatur? " or, in English, "How many pairs of rabbits are born in one year from one pair?" To solve his problem, Leonardo estimated that rabbits have a one-month gestation period and can first mate at the age of one month, so that each female rabbit has its first litter at two months. He made the simplifying assumption that each litter consisted of exactly one male and one female . Leonardo's analysis begins with one pair of baby rabbits, a male and a female. At the end of the first month, these two have reached puberty and mate. There is still one pair of rabbits. At the end of the second month, the female gives birth to a new pair of rabbits. There are now two pairs of rabbits, one pair of adults and one pair of babies. The adult pair mates again, so that they produce one more pair at the end of the third month, at which point there are three pairs of rabbits. One of these pairs has just been born, but the other pairs are old enough to mate, which, being rabbits, they do. At the end of the fourth month, two of the three pairs have babies, so that there are now five pairs of rabbits. Meanwhile, all rabbits born by the previous month mate, so that at the end of the fifth month there are three more pairs of rabbits. Leonardo realized that the number of pairs at the end of each month equaled the sum of the number of pairs the preceding month and the number of pairs the month before that. The rabbits don't simply double in population each month, because it takes two months before a rabbit can have its first litter. Nonetheless, the numbers do grow only slightly more slowly than exponentially; and the process continues indefinitely, at least until you run out of rabbit food or the rabbits take over the world, whichever comes first. The sequence representing the number of pairs each month1, 1, 2, 3, 5, 8, 13, has become known as the Fibonacci series after Leonardo's Latin nickname, Fibonacci (short for filius Bonacci, son of Bonacci). The rabbits aren't so important, but the math is. Each integer in the series is formed by the sum of the two previous integers. The first two integers in the series are 1 and 1.
It's very easy to calculate the Fibonacci sequence by computer. A simple int low = 1; int high = 1; for (int i = 1; i < 40; i++) { System.out.println(low); int temp = high; high = high+low; low = temp; } However, the Fibonacci numbers do grow very large very quickly, and exceed the bounds of an ## Example 3.1 A Program That Calculates the Fibonacci Numbersimport java.math.BigInteger; public class FibonacciNumbers { public static void main(String[] args) { BigInteger low = BigInteger.ONE; BigInteger high = BigInteger.ONE; for (int i = 1; i <= 10; i++) { System.out.println(low); BigInteger temp = high; high = high.add(low); low = temp; } } } When run, Example 3.1 produces the first ten Fibonacci numbers: ` C:\XMLJAVA> java FibonacciNumbers 1 1 2 3 5 8 13 21 34 55 ` It would be straightforward to read the number of Fibonacci numbers to generate from the command line. But because user interfaces aren't the focus of this book, I don't want to obscure the important parts with too much extraneous fluff. |

Processing XML with Javaв„ў: A Guide to SAX, DOM, JDOM, JAXP, and TrAX

ISBN: 0201771861

EAN: 2147483647

EAN: 2147483647

Year: 2001

Pages: 191

Pages: 191

Authors: Elliotte Rusty Harold

- Chapter XI User Satisfaction with Web Portals: An Empirical Study
- Chapter XII Web Design and E-Commerce
- Chapter XV Customer Trust in Online Commerce
- Chapter XVI Turning Web Surfers into Loyal Customers: Cognitive Lock-In Through Interface Design and Web Site Usability
- Chapter XVIII Web Systems Design, Litigation, and Online Consumer Behavior

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net