I have the following code:
public class Main {
public static void Main (String[] args) {
Metodo R = new Metodo();
Scanner entrada = new Scanner(System.in);
int[] valores = new int[10];
int i = 0;
while (i < valores.length) {
System.out.println("Insira um número.");
valores[i] = entrada.nextInt();
i++;
} System.out.println(R.somar(valores));
}
}
public class Metodo {
public int somar(int[] valores) {
int soma = 0, i = 0;
while (i < valores.length) {
if (valores[i] % 2 == 0.5) {
soma = soma + valores[i];
}
i++;
}
return soma;
}
}
For some reason I do not know, it always returns 0, even putting only odd numbers, for example, if I only put the number 1 in all indexes of the array, it should return 10, but returns 0.
How can I resolve it?