Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. public class fib2 {
  2.     public static long getSum(long n) {
  3.         long sum = 0;
  4.                 long temp = 0;
  5.                 long current = 1;
  6.                 long prev = 0;
  7.                
  8.         while(current < n)
  9.                 {
  10.                     temp = current;
  11.                     current = current + prev;
  12.                     prev = temp;
  13.                     if(current % 2 == 0)
  14.                         sum += current;
  15.                 }
  16.         return sum;
  17.     }
  18.     public static void main(String[] args) {
  19.         System.out.println(getSum(4000000));
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement