Advertisement
michael_xgrind

Numeros Primos

Sep 19th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumPrimo {
  4.     public static void main(String args[]){
  5.         Scanner leia = new Scanner(System.in);
  6.         System.out.printf("Entre com a quantidade de numeros primos a ser exibida: ");
  7.         int num = leia.nextInt();
  8.        
  9.         for(int i=1; i<=num; i++){
  10.             Primo(i);
  11.         }
  12.     }
  13.    
  14.     /* funcao */
  15.     public static void Primo (int num){
  16.         int cont = 0;
  17.        
  18.         for(int i=1; i<=num; i++){
  19.             if (num%i==0)
  20.                 cont++;
  21.         }
  22.        
  23.         if (cont==2)
  24.             System.out.printf("\n%d Eh primo", num);
  25.         else
  26.             System.out.printf("\n%d Nao eh primo", num);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement