Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) {
- ArrayList<Integer> A = new ArrayList<>(Arrays.asList(2, 3, 9, 2, 5, 1, 3, 7, 10));
- ArrayList<Integer> B = new ArrayList<>(Arrays.asList(2, 1, 3, 4, 3, 10, 6, 6, 1, 7, 10, 10, 10));
- ArrayList<Integer> C = new ArrayList<Integer>();
- int counter;
- for (Integer i : A) {
- counter = 0;
- for (Integer j : B) {
- if (i.equals(j)) {
- counter++;
- }
- }
- if (counter == 0 || !primeNumbers(counter)) {
- C.add(i);
- }
- }
- System.out.println(C);
- }
- public static boolean primeNumbers(int n) {
- if (n <= 1) {
- return false;
- }
- if (n == 2) {
- return true;
- }
- for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
- if (n % i == 0) {
- return false;
- }
- }
- System.out.println(n);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement