Tino APCS

Lab 9.1 Fibonacci

Background:

The Fibonacci sequence is defined as follows:

Position Fib Number
0 0
1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 21
etc. etc.

Positions 0 & 1 are definition values. For positions greater than 1, the corresponding Fibonacci value of position N = Fib (N-1) + Fib (N-2).

Assignment:

  1. Write a recursive method that takes in a single integer (x >= 0) and returns the appropriate Fibonacci number.
  2. Write a recursive method that solves a multiplication problem of two positive integers.
  3. Write a recursive method that solves a multiplication problem of any two integers, whether positive or negative.

Bonus: Using a return type of int, find the highest Fibonacci number Java can compute on a PC. After finding it, what happens when you try to compute the next Fibonacci number? What's going on?? Can you show exactly how Java got its answer? If you're stuck, the answer lies within Lesson 3, page B.

Instructions:

Use these sample run output values:

  1. Recursive Fibonacci: 0, 3, 11, 20

  2. Recursive multiplication 1: (7 * 8), (5 * 1), (5 * 0), (0 * 9), (0 * 0), (45 * 11)

  3. Recursive multiplication 2: (-7 * 8), (-7 * -8), (7 * -8), (-7 * 9), (-7 * -9), (7 * -9)

Format your output so it looks something like this:

Fib(0) = 0
Fib(3) = 2
...

7*8 = 56
5*1 = 5
5*0 = 0
...

All files must include your name and period in the right format. For example, P3_Wang_Michael_Fibonacci.java Same with the driver.

You must Sign In to submit to this assignment

Last modified: December 12, 2022

Back to Summary

Dark Mode

Outline