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.
 
 
 
 
 
 
Abdelilah Khossan 78e9c1846c
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102)
1 year ago
..
README.md CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) 1 year ago

README.md

StreamReduce

Instructions

Create a file StreamReduce.java.

Create a function sumAll which returns the sum of integers in the stream.
Create a function divideAndAddElements which sums the result of the division, of all the integers in the stream, by 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
$ 

Notions

Stream
Reduce