Guest User

Untitled

a guest
Jul 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class q2evenfibonacci {
  2. public static int ans(int n){
  3. if( n == 0){
  4. return 1;
  5. }
  6. else if(n == 1){
  7. return 2;
  8. }
  9. else{
  10. return ans(n-1) + ans(n-2);
  11. }
  12. }
  13. public static void main(String args[]){
  14. int count = 0;
  15. int answer = 0;
  16. int sum = 0;
  17. while(answer < 4000000){
  18. answer = q2evenfibonacci.ans(count);
  19. if(answer %2 == 0){
  20. sum += answer;
  21. }
  22. count++;
  23. }
  24. System.out.println(sum);
  25. }
  26. }
Add Comment
Please, Sign In to add comment