Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class fib2 {
- public static long getSum(long n) {
- long sum = 0;
- long temp = 0;
- long current = 1;
- long prev = 0;
- while(current < n)
- {
- temp = current;
- current = current + prev;
- prev = temp;
- if(current % 2 == 0)
- sum += current;
- }
- return sum;
- }
- public static void main(String[] args) {
- System.out.println(getSum(4000000));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement