My intention is as follows = The user passes us an array of ints (called enters) and we, using a method, have to return an array with the values he has entered, with those that are repeatedly deleted. Here is my code:
public int [] norepeticions (int [] enters) {
int contador=0;//longitud del nuevo array
int[] unics=null;//array donde estaran los numeros sin repetir
// In this loop we define the length of the new array (where the numbers go without repeating
for (int i = 0; i < enters.length-1; i++) {
if(enters[i]==enters[i+1]){
contador++;
}
}
unics=new int[contador];
// in this loop we fill the array with the numbers without repeating
for (int i = 0; i < enters.length-1; i++) {
if(enters[i]==enters[i+1]){
unics[i]=enters[i];
}
}
return unics;
}
and the output is as follows:
Array content entered by user: [1 2 3 2] array without repetitions: []
My question is: what have I failed to do? Am I wrong? Is there any other way to do it?