void (Integer num) { Stream<Integer> numbers = IntStream.rangeClosed(1,num).boxed(); Stream<Triplet<Integer, Integer, Integer>> triangles = numbers.flatMap(x -> { return IntStream.rangeClosed(1, x).boxed().flatMap(y -> { return IntStream.rangeClosed(1, y).boxed().filter(z -> { return x * x == y * y + z * z; }).map(z1 -> new Triplet<Integer, Integer, Integer>(x, y, z1)); }); }); triangles.forEach(System.out::println); }