Skip to content

Instantly share code, notes, and snippets.

@rakeshopensource
Created April 5, 2018 08:10
Show Gist options
  • Save rakeshopensource/d9a8776f60d89836817a6a05c1d88f4d to your computer and use it in GitHub Desktop.
Save rakeshopensource/d9a8776f60d89836817a6a05c1d88f4d to your computer and use it in GitHub Desktop.
Prime numbers with Java8 Stream API
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