Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
import java.util.stream.*;
Silly reminider of streams
Stream sum of even numbers includeing 2 up to including N. Go to the Java streams cheat sheet for more.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// {
public class Main {
public static void main(String[] args) {
// }
int N=4;
System.out.println(IntStream.rangeClosed(2,N).filter(x -> x%2==0).sum());
// 6
//{
}
}
//}
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content