Guest User

Exercicio3

a guest
May 22nd, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Random;
  2. public class exercicio3 {
  3.  
  4.     /**
  5.      * @param args
  6.      */
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         int[] k = new int[15], p = new int [15];
  10.         int soma = 1, total = 0;
  11.         Random rand = new Random();
  12.         boolean ehPrimo = true;
  13.        
  14.         for (byte i = 0; i < 15; i++){
  15.             k[i] = rand.nextInt(20);
  16.             total = k[i] / 2;
  17.             while (soma != total){
  18.                 if (k[i] % soma == 0 && (soma != k[i] || soma != 1)){
  19.                     ehPrimo = false;
  20.                     break;
  21.                 }
  22.                 soma++;
  23.             }
  24.             if (ehPrimo == true){
  25.                 p[i] = k[i];
  26.             }
  27.             ehPrimo = true;
  28.             System.out.print(p[i] + ",");
  29.         }
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment