Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 25, 2022 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e52a5297005ab4eca2db438f235b0bfb to your computer and use it in GitHub Desktop.
Save parzibyte/e52a5297005ab4eca2db438f235b0bfb to your computer and use it in GitHub Desktop.
public static void sumaParesImpares() {
int sumaPares = 0;
int sumaImpares = 0;
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
System.out.printf("Ingresa un número entero (%d de 10): ", i + 1);
int numero = sc.nextInt();
if (numero % 2 == 0) {
sumaPares += numero;
} else {
sumaImpares += numero;
}
}
sc.close();
System.out.printf("Resultado: Total pares: %d; Total impares: %d", sumaPares, sumaImpares);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment