| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... * *
By considering the terms in the Fibonacci sequence whose values do not exceed four million, * find the sum of the even-valued terms. * *
Link: https://projecteuler.net/problem=2 */ public class Problem02 { public static void main(String[] args) { int[][] testNumbers = { {10, 10}, /* 2 + 8 == 10 */ {15, 10}, /* 2 + 8 == 10 */ {2, 2}, {1, 0}, {89, 44} /* 2 + 8 + 34 == 44 */ }; for (int[] ints : testNumbers) { assert solution1(ints[0]) == ints[1]; } } private static int solution1(int n) { int sum = 0; int first = 1; int second = 2; while (second
| Back | FazBrowse Home | New Git URL |