{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

15-section-2 - Mehran Sahami CS 106A Handout#15 Section...

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

View Full Document Right Arrow Icon
Mehran Sahami Handout #15 CS 106A October 10, 2011 Section Handout #2 Simple Java Portions of this handout by Eric Roberts 1. The Fibonacci sequence In the 13th century, the Italian mathematician Leonardo Fibonacci as a way to explain the geometic 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: This program continues as long as the value of the term is less than the maximum value, so that the loop construct you need is a while , presumably with a header line that looks like this: while (term < MAX_TERM_VALUE) Note that the maximum term value is specified using a named constant.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern