Question: The example of Fig. 17.7 summed the triples of the even integers from 2 through 10. We used filter and map in the stream pipeline

The example of Fig. 17.7 summed the triples of the even integers from 2 through 10. We used filter and map in the stream pipeline to demonstrate both in one stream pipeline. Reimplement Fig. 17.7’s stream pipeline using only map (similar to Fig. 17.4).

Fig. 17.7

1 // Fig. 17.7: StreamFilterMapReduce.java 2 // Triple the even ints from 2 through 10 then sum them with

Fig. 17.4

I // Fig. 17.4: StreamMapReduce.java 2 // Sum the even integers from 2 through 20 with IntStream. 3 import

1 // Fig. 17.7: StreamFilterMapReduce.java 2 // Triple the even ints from 2 through 10 then sum them with IntStream. import java.util.stream. IntStream; 3 4 5 6 9 10 [1 12 13 public class StreamFilterMapReduce { public static void main(String[] args) { // sum the triples of the even integers from 2 through 10 System.out.printf( "Sum of the triples of the even ints from 2 through 10 is: %d%n", IntStream.rangeClosed (1, 10) .filter(x -> x % 2 == 0) .map(x -> x * 3) .sum()); 14 15 } } Sum of the triples of the even ints from 2 through 10 is: 90

Step by Step Solution

3.33 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question is asking to modify the stream pipeline from Figure 177 so that it no longer uses the f... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java How To Program Late Objects Questions!