Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dvt32/1152cc4aadf7cab9c76e8d9748f184b3 to your computer and use it in GitHub Desktop.
Save dvt32/1152cc4aadf7cab9c76e8d9748f184b3 to your computer and use it in GitHub Desktop.
ALGORITHMO #11 - Sieve of Eratosthenes Algorithm Implementation
public class Solution {
static void sieveOfEratosthenes(int n) {
boolean sieve[] = new boolean[n+1];
int i = 2, j = 0;
while (i <= n) {
if (sieve[i] == false) {
System.out.print(i + " ");
j = i * i;
while (j <= n) {
sieve[j] = true;
j += i;
}
}
++i;
}
}
public static void main(String[] args) {
sieveOfEratosthenes(199);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment