Multithreaded processing of data streams with grouping and filtering

Java Hard streams

Task «Multithreaded processing of data streams with grouping and filtering»

Write a program that reads from standard input lines containing integers separated by spaces. Each line represents a separate data stream. It is necessary to process all streams using Java Streams, combine them into a single stream, filter positive numbers, square them, group them by the remainder of division by 5, and for each group calculate the arithmetic mean. Output the result in ascending order of the remainder. If there are no numbers for a remainder, output 0. It is guaranteed that the input data contains no more than 1000 numbers.

Input Format

Several lines, each line contains integers separated by spaces. The end of input is an empty line.

Output Format

5 lines, each containing a floating-point number (arithmetic mean) for the corresponding remainder from 0 to 4. The output must be formatted with two decimal places.

Examples

Example 1

INPUT
3 1 2
OUTPUT
1,2,3

Example 2

INPUT
1 2 3 4 5 6 7 8 9 10
OUTPUT
5.00 6.00 7.00 8.00 9.00

Example 3

INPUT
5 5 5
OUTPUT
5,5,5

Example 4

INPUT
-1 -3 0 2
OUTPUT
-3,-1,0,2
main.java