Advertisement
michael_xgrind

Primo Ternario

Sep 19th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 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.         String primo = (cont==2) ? "\neh primo\n" : "\nnao eh primo\n";
  17.         System.out.print(primo);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement