public void ingresoMatrices() {
m = Integer.parseInt(JOptionPane.showInputDialog("Escriba el numero de filas de la Matriz A"));
n = Integer.parseInt(JOptionPane.showInputDialog("Escriba el numero de columnas de la Matriz A"));
matrizA = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
matrizA[i][j] = Integer.parseInt(JOptionPane.showInputDialog("MATRIZ A:\n Escriba el numero de la fila " + (i + 1) + " y la columna" + (j + 1)));
}
}
m1 = Integer.parseInt(JOptionPane.showInputDialog("Escriba el numero de filas de la Matriz B"));
n1 = Integer.parseInt(JOptionPane.showInputDialog("Escriba el numero de columnas de la Matriz B"));
matrizB = new int[m1][n1];
for (int x = 0; x < m1; x++) {
for (int y = 0; y < n1; y++) {
matrizB[x][y] = Integer.parseInt(JOptionPane.showInputDialog("MATRIZ B:\n Escriba el numero de la fila " + (x + 1) + " y la columna" + (y + 1)));
}
}
}
public void multiplica() {
int matrizResultado[][] = new int[m][n1];
if (n == m1) {
int suma = 0;
for (int i = 0; i < matrizA.length; i++) {
for (int k = 0; k < matrizB[0].length; k++) {
suma = 0;
for (int j = 0; j < matrizA[0].length; j++) {
suma += (matrizA[i][j] * matrizB[j][k]);
}
matrizResultado[i][k] = suma;
}
}
} else {
areaTexto.setText("No se puede efectuar la operación,\n las matrices"
+ " no tienen la dimensión adecuada");
return;
}
mostrarResultado(matrizResultado);
}
public void mostrarResultado(int matriz[][]) {
String salida = "";
for (int i = 0; i < matriz.length; i++) {
for (int j = 0; j < matriz[i].length; j++) {
salida += matriz[i][j] + "\t";
}
salida += "\n";
}
areaTexto.setText(salida);
areaTexto.setEditable(false);
}
}