Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public class Prova {
  2. public static void main(String[] args) {
  3. int nnumerip = 0;
  4. for (int numero = 1; numero <= 1000; numero++) {
  5. if (controllanumeriprimi(numero) == -1) {
  6. } else if (nnumerip == 40) {
  7. System.out.println("Interrompendo il loop");
  8. break;
  9. } else {
  10. nnumerip++;
  11. System.out.println(numero + " è un numero primo");
  12. }
  13. }
  14. }
  15.  
  16. public static int controllanumeriprimi(int numero) {
  17. if (numero == 1) {
  18. return -1;
  19. }
  20. for (int a = 2; a <= numero / 2; a++) {
  21. if (numero % a == 0) {
  22. return -1;
  23. }
  24. }
  25. return numero;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement