Multiplicacion de 2 Matrices

También podría gustarte

Está en la página 1de 3

package actividad4;

import javax.swing.JOptionPane;

public class Actividad4 {

public static void main(String[] args) {

int n,m,x,y;

n= Integer.parseInt(JOptionPane.showInputDialog("Ingrese el valor de las filas de la primera


matriz"));

m= Integer.parseInt(JOptionPane.showInputDialog("Ingrese el valor de las columnas de la


primera matriz"));

x= Integer.parseInt(JOptionPane.showInputDialog("Ingrese el valor de las filas de la segunda


matriz"));

y=Integer.parseInt(JOptionPane.showInputDialog("Ingrese el valor de las columnas de la


segunda matriz"));

int M1 [][]=new int [n][m];

int M2 [][]=new int [x][y];

int M3 [][]=new int [n][y];

int i,j = 0;

for (i=0; i<M1.length;i++){

for(j=0; j<M1[i].length; j++){

JOptionPane.showInputDialog("Ingrese el numero de la fila " + i + "y columna " + j + ": ");


}

for (i=0; i<M2.length;i++){

for(j=0; j<M2[i].length; j++){

JOptionPane.showInputDialog("Ingrese el numero de la fila " + i + "y columna " + j + ": ");

if(m==x){

System.out.println("La matriz resultante es: ");

for(int ii=0;ii<n;ii++){

System.out.print("[ ");

for(int jj=0;jj<y;jj++){

for(int h=0;h<m;h++){

M3[i][j]+=M1[i][h]*M2[h][j];

System.out.print(M3[i][j]+" ");

System.out.println("");

}
else{

JOptionPane.showMessageDialog(null,"La multiplicacion no se puede realizar ");

También podría gustarte