fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class FibonacciEven {
  8.  
  9. public static void main(String[] args) {
  10. int num=4000000;
  11. int fib=0;
  12. int t2=2;
  13. int t1=1;
  14. int sum=2;
  15. while (fib<num) {
  16. fib=t1+t2;
  17. t1=t2;t2=fib;
  18. if(fib<num)
  19. if(fib%2==0)
  20. sum+=fib;
  21. }
  22. System.out.println(sum) ;
  23. }
  24.  
  25. }
  26.  
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
4613732