Write a function or method that detects if a number is repeated in an array, at least a certain number of times. The function must receive the arrangement, the number to be detected and the number of minimum times that must appear.
Example:
For arrangement = [4, 5, 2, 4, 5, 9, 9, 4, 4]
contiene(arreglo, 4, 5) // Regresa false;
contiene(arreglo, 4, 4) // Regresa true;
contiene(arreglo, 4, 3) // Regresa true;
contiene(arreglo, 9, 2) // Regresa true;
This is the code of what I tried:
public static void main(String[] args) {
int[] array = {1, 2, 2, 3, 6, 4, 4, 4, 9, 5, 6, 5, 9, 2};
list = new int[array.length];
for (int i = 0; i < array.length; i++) {
int count = 0;
for (int j = 0; j < array.length; j++) {
if (array[i] == array[j]) {
count++;
if (numero(array[i])) {
list[i] = array[i];
}
}
}
if (list[i] != 0) {
System.out.println(list[i] + " it has been found " + count + " times");
}
}
}
public class DuplicatedDataInArray {
static int[] list;
static boolean numero(int num) {
for (int i = 0; i < list.length; i++) {
if (list[i] == num) {
return false;
}
}
return true;
}
}