mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
davhojt
1cf114eb85
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
StreamReduce
Instructions
Create a file StreamReduce.java
.
Create a function sumAll
which returns sum of integers in the stream.
Create e function divideAndAddElements
which sum the result of the division between all the integers in the stream and the divider.
Expected Functions
public class StreamReduce {
public static Integer sumAll(Stream<Integer> s) {
// your code here
}
public static Integer divideAndAddElements(Stream<Integer> s, int divider) {
// your code here
}
}
Usage
Here is a possible ExerciseRunner.java to test your function :
import java.io.IOException;
import java.util.stream.Stream;
public class ExerciseRunner {
public static void main(String[] args) throws IOException {
System.out.println(StreamReduce.sumAll(Stream.of(3, 5, 7, 10)));
System.out.println(StreamReduce.sumAll(Stream.of()));
System.out.println(StreamReduce.divideAndAddElements(Stream.of(3, 5, 7, 10), 2));
System.out.println(StreamReduce.divideAndAddElements(Stream.of(), 2));
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
25
0
11
0
$