eniallator

Project Euler | Problem 2

Sep 26th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. public class Prob2 {
  2.     public static void main(String[ ] args) {
  3.         int a = 0;
  4.         int b = 1;
  5.         int sum = 0;
  6.  
  7.         while (b < 4000000) {
  8.             sum += (b & 1) == 0 ? b : 0;
  9.  
  10.             int temp = a;
  11.             a = b;
  12.             b = temp + b;
  13.         }
  14.  
  15.         System.out.println(sum);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment