Created
April 17, 2020 16:11
-
-
Save parzibyte/76a72589320f71f4be04f738aad284ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
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