Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created March 5, 2017 18:35
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 folivetti/b5f999b42f37912b59e8f6715ab8be1f to your computer and use it in GitHub Desktop.
Save folivetti/b5f999b42f37912b59e8f6715ab8be1f to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class Main {
public static boolean ehPrimo(int n) {
boolean primo = true;
int i;
for (i=2;i<n;i++) {
if (n%i == 0) {
primo = false;
i=n;
}
}
return primo;
}
public static void main(String[] args) {
int n, i, total;
Scanner leitor = new Scanner(System.in);
n = leitor.nextInt();
i = 2;
total = 0;
while (total<=n) {
if (ehPrimo(i)) {
System.out.println(i);
total++;
}
i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment