Created
May 9, 2018 06:25
-
-
Save BrendenHJH/0b8a93fde9f0a09ca76e20ab6bf88b6c to your computer and use it in GitHub Desktop.
에라토스테네스의 체(Sieve of Eratosthenes)
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
import java.util.ArrayList; | |
public class Main { | |
public static final int MAX = 25; | |
public static void main(String[] args) { | |
ArrayList<Integer> primeList = new ArrayList<Integer>(); | |
boolean isPrime[] = new boolean[MAX + 1]; | |
for(int i = 2; i <= MAX; i++) { | |
isPrime[i] = true; | |
} | |
for(int i = 2; i <= MAX; i++) { | |
if(!isPrime[i]) continue; | |
else primeList.add(i); | |
for(int j = i*2; j <= MAX; j += i) { | |
isPrime[j] = false; | |
} | |
} | |
for(int i = 0; i < primeList.size(); i++) { | |
System.out.println(primeList.get(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment