| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/loisoft/Java/master/ProjectEuler/Problem02.java | [Back] [Original] |
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
| Web Proxy Viewer | New URL | Original Page |