Skip to content

Instantly share code, notes, and snippets.

@notpushkin
Created March 5, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notpushkin/9370786 to your computer and use it in GitHub Desktop.
Save notpushkin/9370786 to your computer and use it in GitHub Desktop.
import java.util.*;
class Primes {
public static void main(String args[]) {
int n = 100000, status = 1, num = 3;
if (n >= 1) {
System.out.println("First "+n+" prime numbers are :-");
System.out.println(2);
}
for (int count = 2; count <=n ;) {
for (int j = 2; j <= Math.sqrt(num); j++) {
if (num%j == 0) {
status = 0;
break;
}
}
if (status != 0) {
System.out.println(num);
count++;
}
status = 1;
num++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment