SHARE
TWEET

1 algorithm task

Miszak Apr 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Test {
  2.     public static void main(String[] args) {
  3.  
  4.  
  5.         ArrayList<Integer> A = new ArrayList<>(Arrays.asList(2, 3, 9, 2, 5, 1, 3, 7, 10));
  6.         ArrayList<Integer> B = new ArrayList<>(Arrays.asList(2, 1, 3, 4, 3, 10, 6, 6, 1, 7, 10, 10, 10));
  7.         ArrayList<Integer> C = new ArrayList<Integer>();
  8.  
  9.         int counter;
  10.         for (Integer i : A) {
  11.             counter = 0;
  12.             for (Integer j : B) {
  13.                 if (i.equals(j)) {
  14.                     counter++;
  15.                 }
  16.             }
  17.             if (counter == 0 || !primeNumbers(counter)) {
  18.                 C.add(i);
  19.             }
  20.         }
  21.         System.out.println(C);
  22.  
  23.  
  24.     }
  25.  
  26.     public static boolean primeNumbers(int n) {
  27.         if (n <= 1) {
  28.             return false;
  29.  
  30.         }
  31.         if (n == 2) {
  32.             return true;
  33.         }
  34.         for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
  35.             if (n % i == 0) {
  36.                 return false;
  37.             }
  38.         }
  39.         System.out.println(n);
  40.         return true;
  41.  
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top