Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 17, 2020 16:11
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/76a72589320f71f4be04f738aad284ee to your computer and use it in GitHub Desktop.
Save parzibyte/76a72589320f71f4be04f738aad284ee to your computer and use it in GitHub Desktop.
/*
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
Copyright (c) 2020 Luis Cabrera Benito
Licenciado bajo la licencia MIT
El texto de arriba debe ser incluido en cualquier redistribución
* */
package me.parzibyte;
public class Main {
public static void main(String[] argumentos) {
int[][] matrizA = {
{3, 2, 1},
{1, 1, 3},
{0, 2, 1},
};
int[][] matrizB = {
{2, 1},
{1, 0},
{3, 2},
};
//Lugar en donde se almacena el resultado
int[][] producto = new int[matrizB.length][matrizB[0].length];
// Necesitamos hacer esto por cada columna de la segunda matriz (B)
for (int a = 0; a < matrizB[0].length; a++) {
// Dentro recorremos las filas de la primera (A)
for (int i = 0; i < matrizA.length; i++) {
int suma = 0;
// Y cada columna de la primera (A)
for (int j = 0; j < matrizA[0].length; j++) {
// Multiplicamos y sumamos resultado
suma += matrizA[i][j] * matrizB[j][a];
}
// Lo acomodamos dentro del producto
producto[i][a] = suma;
}
}
// Recorrer producto
System.out.print("Imprimiendo producto\n");
for (int i = 0; i < matrizB.length; i++) {
for (int j = 0; j < matrizB[0].length; j++) {
System.out.printf("%d ", producto[i][j]);
}
System.out.print("\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment