Last active
January 14, 2017 21:46
-
-
Save dvt32/1152cc4aadf7cab9c76e8d9748f184b3 to your computer and use it in GitHub Desktop.
ALGORITHMO #11 - Sieve of Eratosthenes Algorithm Implementation
This file contains 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
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