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:

Related Posts:

  • Problem Set 3 The below questions are very interesting and amazing questions. So please do try it. QUESTION 1 int a=5,*b=&a;printf("%d",a**b); !-- google_ad_client = "ca-pub-0770336576285658"; /* inside post */ goog… Read More
  • Problem Set Java  Predict the Output    Question 1 class Base { public void Print() { System.out.println("Base"); } } class Derived extends Base { public void Print() { System.out.println("D… Read More
  • Find the largest sum in an Array Problem $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); div.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; … Read More
  • 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 sumofE… Read More
  • Problem No.1 The below program is hideously slow. CAN YOU SPOT THE REASON? public static void main(String args[]){ Long sum=0L; for ( long i=0; i < Integer.MAX_VALUE; i++){ sum += i; } System.out.pri… Read More