Entering Starfleet Academy
From Huben's Wiki
Line 67: | Line 67: | ||
== Challenges! == | == Challenges! == | ||
− | + | * In a Fibonacci sequence, each term is the sum of the previous two terms. That's recursion: to find a term, we find the preceding two terms and add them. That breaks the problem into two simpler parts, calling itself to calculate each of the simpler parts. In algebra, we say fib(n) = fib(n-1) + fib(n-2). So when do we stop? We are told fib(1) = 1 and fib(0) = 0. The sequence is 0, 1, 1, 2, 3, 5, 8, 13.... | |
− | spacing | + | ** Write a class Fibonacci with a main() that prints fib(6). |
− | + | ** Write a method '''public static int fib(int n)'''. That method should return 1 if n is 1, and 0 if n is 0. Otherwise, it should return the sum of the preceding two Fibonacci numbers. | |
− | + | * Change the spacing of the rectangles so that they are closer or further apart. | |
+ | * The rectangle shrink concentrically. Make them shrink eccentrically, to one corner or another. | ||
+ | * Can you make the rectangles change color as they shrink? |