Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mingbackmountain/582904c9db9555d1e1191d8b8e926717 to your computer and use it in GitHub Desktop.
Save mingbackmountain/582904c9db9555d1e1191d8b8e926717 to your computer and use it in GitHub Desktop.
public class Oldcode {
private static boolean prime[] = new boolean[1000000];
private static int n;
public static void delete(int i) {
for (int index = i+1; index < n; ++index) {
if(index%i == 0) {
prime[index] = false;
}
}
}
public static void main(int argc,String argv) {
Oldcode.n = Integer.parseInt(argv);
for (int i = 2; i <= n; i++) {
prime[i] = true;
if(prime[i]==true) {
delete(i);
}
}
for(int i = 2;i<=n;i++) {
if(prime[i]==true) {
System.out.println(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment