Task 2 of 7 · 0 solved · 7 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

11.4 Lambdas and streams — count with a predicate

Total: 0 / 3 pts
Practice mode — check each part and get hints as you go.
Task

Fill in countMatching so that it returns how many elements satisfy the predicate p.

The caller supplies a lambda: x -> x > 0 counts positives, x -> x % 2 == 0 counts evens — the same method, different behaviour passed in. The program prints 3 and then 2.

Your solution