11/26/11

Java Problem Set 2

Write a function which calculates the sum of even Fibonacci numbers.

public static void main(String args[]) {
    for(int i=1;i<22;i++)
        System.out.print(sumofEvenFibonacci(i) + " ");
}

public static long sumofEvenFibonacci(int n) {
    // add your code here.
    return sum;
}

prints

0 0 2 2 2 10 10 10 44 44 44 188 188 188 798 798 798 3382 3382 3382 14328



-->
--> [Click for sample solution]

SHARE THIS POST: