The product of squares

Report a typo

Write a collector that evaluates the product of the squares of the integer numbers in a Stream<Integer>.

Important. You should write only the collector in any valid format but without ";" on the end.

It will be passed as an argument to the collect() method of a stream as shown below.

List<Integer> numbers = ...
long val = numbers.stream().collect(...your_collector_will_be_passed_here...);

Examples of valid solution formats: Collectors.reducing(...) or reducing(...).

Sample Input 1:

0 1 2 3

Sample Output 1:

0

Sample Input 2:

1 2

Sample Output 2:

4
Write a program in Java 17
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

class CollectorProduct {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

String[] values = scanner.nextLine().split(" ");

List<Integer> numbers = new ArrayList<>();
for (String val : values) {
numbers.add(Integer.parseInt(val));
}

long val = numbers.stream().collect(
// Write your collector here
);

System.out.println(val);
}
}
___

Create a free account to access the full topic