Good I have this problem: from an array and a number determine which number of the array is closest to the number. I do not get it
public static int masCercano(int[] numeros, int num)
{
int cercano = 0;
for (int i = 0; i < numeros.length; i++)
{
if (numeros[i] == num)
{
return numeros[i];
}
else
if (numeros[i] > num || numeros[i] < num)
{
cercano = numeros[i];
if (cercano > numeros[i])
{
cercano = numeros[i];
}
else
cercano = numeros[i];
}
}
return cercano;
}