Question

use java streams to find a general integral using simpsons method. use paralell streams if possible.

use java streams to find a general integral using simpsons method. use paralell streams if possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//a simple program to demonstrate the use of stream in java

import java.util.*;

import java.util.stream.*;

  

class Demo

{

  public static void main(String args[])

  {

  

    // create a list of integers

    List<Integer> number = Arrays.asList(2,3,4,5);

  

    // demonstration of map method

    List<Integer> square = number.stream().map(x -> x*x).

                           collect(Collectors.toList());

    System.out.println(square);

  

    // create a list of String

    List<String> names =

                Arrays.asList("Reflection","Collection","Stream");

  

    // demonstration of filter method

    List<String> result = names.stream().filter(s->s.startsWith("S")).

                          collect(Collectors.toList());

    System.out.println(result);

  

    // demonstration of sorted method

    List<String> show =

            names.stream().sorted().collect(Collectors.toList());

    System.out.println(show);

  

    // create a list of integers

    List<Integer> numbers = Arrays.asList(2,3,4,5,2);

  

    // collect method returns a set

    Set<Integer> squareSet =

         numbers.stream().map(x->x*x).collect(Collectors.toSet());

    System.out.println(squareSet);

  

    // demonstration of forEach method

    number.stream().map(x->x*x).forEach(y->System.out.println(y));

  

    // demonstration of reduce method

    int even =

       number.stream().filter(x->x%2==0).reduce(0,(ans,i)-> ans+i);

  

    System.out.println(even);

  }

Any problem pls comment it

Add a comment
Know the answer?
Add Answer to:
use java streams to find a general integral using simpsons method. use paralell streams if possible.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT