package Uebungen.Uebung4;

import java.util.Arrays;
public class Schnittmenge {
    public static void main(String[] args){
        //Scanner scanner = new Scanner(System.in);
        int[] set1a = {0, 1, 2, 3, 4, 5};
        int[] set1b = {3, 4, 5, 6, 7, 8};
        int[] set2a = {0, 1, 2, 3};
        int[] set2b = {4, 5, 6};
        int[] set3a = {0, 1, 2};
        int[] set3b = {0, 1, 2};
        System.out.println(Arrays.toString(schnittmenge(set1a, set1b)));
        System.out.println(Arrays.toString(schnittmenge(set2a, set2b)));
        System.out.println(Arrays.toString(schnittmenge(set3a, set3b)));

    }

    public static int[] schnittmenge(int[] arrA,int[] arrB){
        int resArrSize = 0;
        for(int numberA:arrA){
            for(int numberB:arrB){
                if(numberA==numberB) resArrSize++;
            }
        }
        int[] resultArr = new int[resArrSize];
        for(int numberA:arrA){
            for(int numberB:arrB){
                if(numberA==numberB) resultArr[--resArrSize] = numberA;
            }
        }
        return resultArr;
    }
}
