Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 24, 2021 22:58
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/130e4ccbd0e222334b4266301e95fb41 to your computer and use it in GitHub Desktop.
Save parzibyte/130e4ccbd0e222334b4266301e95fb41 to your computer and use it in GitHub Desktop.
static void sumaColumnas(int[][] matriz) {
// Imprimir la matriz normalmente
imprimirMatriz(matriz);
// Debajo de ella imprimir una línea divisora
for (int x = 0; x < matriz[0].length; x++) {
System.out.print("___");
}
System.out.println();
// Luego recorrer por columna y sumar
for (int x = 0; x < matriz[0].length; x++) {
int suma = 0;
for (int y = 0; y < matriz.length; y++) {
suma += matriz[y][x];
}
System.out.printf("%d ", suma);
}
System.out.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment