I was trying to do this program, the main problem is that it only lets me enter the value I want to give to numeroN
, then it does not let me write by console and in the summation I get that is equal to zero, I wanted to know if someone can tell me what I'm wrong about.
// Hacer un programa que permita sumar los primeros numeros N pares.
int numeroN = 0;
int numero = 0;
int sumatoria = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Ingrese el valor que desea asignarle al numero N : ");
numeroN = sc.nextInt();
for (int i = 1; i < numeroN; i++) {
System.out.println("Ingrese un numero : ");
if ((numero % 2) != 0) {
numero = sc.nextInt();
}
else if ((numero % 2) == 0) {
System.out.println("Error! El numero ingresado es par.");
}
sumatoria += numero;
}
System.out.println("La sumatoria es : " + sumatoria);