Advertisement
michael_xgrind

Primo

Sep 19th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 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 o numero: ");
  7.         int num = leia.nextInt();
  8.         int cont = 0;
  9.        
  10.         for(int i=1; i<=num; i++){
  11.             if (num%i==0){
  12.                 cont++;
  13.             }
  14.         }
  15.        
  16.         if(cont==2){
  17.             System.out.printf("\n%d eh primo\n", num);
  18.         } else {
  19.             System.out.printf("\n%d nao eh primo\n", num);
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement