solution to problem 3 using Java 8 streams