Solution in Java

public List<Integer> output(int[] num) {
    List<Integer> out = new ArrayList<Integer>();
    for (int i = 0; i < num.length; j++) {
        for (int j = i + 1; j < num.length; j++) {
            if (num[j] == num[i]) {
                if (!contains(out, num[j])) out.add(num[j]);
            }
        }
    }
    return out;
}

private boolean contains(List<Integer> out, int numj) {
    for (int i = 0; i < out.size(); i++) {
        if (out.get(i) == numj)
            return true;
    }
    return false;
}