Created
April 5, 2018 08:10
-
-
Save rakeshopensource/d9a8776f60d89836817a6a05c1d88f4d to your computer and use it in GitHub Desktop.
Prime numbers with Java8 Stream API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
public class Prime { | |
public static void main(String[] args) { | |
IntStream.rangeClosed(1, 100) | |
.filter(i -> IntStream.rangeClosed(2, (int) Math.sqrt(i)) | |
.noneMatch(j -> i % j == 0 && i != 1) | |
) | |
.forEach(System.out::println); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment