Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Prova {
- public static void main(String[] args) {
- int nnumerip = 0;
- for (int numero = 1; numero <= 1000; numero++) {
- if (controllanumeriprimi(numero) == -1) {
- } else if (nnumerip == 40) {
- System.out.println("Interrompendo il loop");
- break;
- } else {
- nnumerip++;
- System.out.println(numero + " è un numero primo");
- }
- }
- }
- public static int controllanumeriprimi(int numero) {
- if (numero == 1) {
- return -1;
- }
- for (int a = 2; a <= numero / 2; a++) {
- if (numero % a == 0) {
- return -1;
- }
- }
- return numero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement