I have problem with method filter. I can't filter out values less than 4,000,000. Do you have any ideas?
public class Euler2 {
public static void main(String[] args) {
long sum = calculateSumOfTheEvenValuesOfTheFibonacciSequence();
System.out.println(sum);
}
static long calculateSumOfTheEvenValuesOfTheFibonacciSequence() {
return Stream.iterate(new Long[]{1L, 2L}, x -> new Long[]{x[1], x[0] + x[1]})
.flatMap(Arrays::stream)
.filter(new Predicate<Long>() {
@Override
public boolean test(Long x) {
if (x < 4_000_000) {
return true;
} else {
return false;
}
}
})
.filter(x -> x % 2 == 0)
.reduce(0L, Long::sum);
}
}