Project Euler #2: Even Fibonacci numbers

  • + 0 comments
    public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int t = in.nextInt();
            for(int a0 = 0; a0 < t; a0++){
                long n = in.nextLong();
                ArrayList<Long> arrL = new ArrayList<>();
                long before = 0;
                long help = 0;
                for (long i = 1; i <= n;) {
                    if(i % 2 == 0) {
                        arrL.add(i);
                    }
                    help = i;
                    i += before;
                    before = help;
                }
                System.out.println(arrL.stream().mapToLong(a -> a).sum());
                
            }
        }