package fall23.Week4; /** * In this week's club bonus challenges, you will be tasked with solving problems relating to the Fibonacci Sequence. * * For those unfamiliar, the Fibonacci Seuqence is generated by adding the prior two terms. Starting with 1 & 2, The * first 10 terms are 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. */ public class Week4 { /** * Only consider terms of the Fibonacci Sequence below 4 million. Find the sum of only the even terms. * eg. The first 5 terms counted would be 2, 8, 34, 144, 610, . . ., and the sum of those terms is 366. * * Credit: Project Euler Problem 2. * HINT: If your algorithm works for terms below 200, it'll work for the terms below any value. */ public static int problem1() { return -1; // TODO } /** * Write an algorithm that will calculate the nth EVEN term of the Fibonacci Sequence. * * HINT: This only requires a minor modification to your solution for Problem1. */ public static int problem2(int n) { return -1; // TODO } /** * Write an algorithm that finds the first EVEN term of the Fibonacci Sequence that has n digits. * eg. if n = 3, value = 144. * * Then, find the average of all of the EVEN terms up to this value. */ public static double problem3(int n) { return -1.0; // TODO } /** * Test driver should not be edited! */ public static void main(String[] args) { int sum1 = problem1(); int sum2 = problem2(10); double avg3 = problem3(5); System.out.println(sum1 == 4613732 ? "Problem 1 is correct!" : "Problem 1 (" + sum1 + ") is not correct..."); System.out.println(sum2 == 196418 ? "Problem 2 is correct!" : "Problem 2 (" + sum2 + ") is not correct..."); System.out.println(avg3 == 2046.0 ? "Problem 3 is correct!" : "Problem 3 (" + avg3 + ") is not correct..."); } }