14-section-1

# 14-section-1 - CS 106A Handout#14 Section Handout#1-Simple...

This preview shows pages 1–2. Sign up to view the full content.

Handout #14 CS 106A June 30, 2009 Section Handout #1—Simple Java This week in section, you will write two programs that get you started with Java. 1. The Fibonacci sequence In the 13th century, the Italian mathematician Leonardo Fibonacci—as a way to explain the geometric growth of a population of rabbits—devised a mathematical sequence that now bears his name. The first two terms in this sequence, Fib (0) and Fib (1), are 0 and 1, and every subsequent term is the sum of the preceding two. Thus, the first several terms in the Fibonacci sequence look like this: Fib (0) = 0 Fib (1) = 1 Fib (2) = 1 (0 + 1) Fib (3) = 2 (1 + 1) Fib (4) = 3 (1 + 2) Fib (5) = 5 (2 + 3) Write a program that displays the terms in the Fibonacci sequence, starting with Fib (0) and continuing as long as the terms are less than 10,000. Thus, your program should produce the following sample run: Fibonacci This program lists the Fibonacci sequence. 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 This program continues as long as the value of the term is less than the maximum value,

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern