Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimeSieve {
- public static void print(int a) {
- System.out.println(a);
- }
- static int size = 1000000;
- static boolean[] arrayList = new boolean[size+1];
- public static void main(String args[]) {
- // set all values to true
- for (int i = 2; i <= size; i++) { arrayList[i] = true; }
- // remove non-primes
- for (int i = 2; i*i <= size; i++) {
- if (arrayList[i]) {
- for (int j = i; i*j <= size; j++) { arrayList[i*j] = false; }
- }
- }
- // print off the primes
- for (int i = 0; i < arrayList.length; i++) {
- if (arrayList[i] == true) { print(i); }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement