More Related Content
More from Chaitanya Rajkumar Limmala
More from Chaitanya Rajkumar Limmala (16)
Java Week2(B) Notepad
- 1. JAVA WEEK2(B)
/* Week 2 : b) Write a Java program to multiply two given matrices. */
import javax.swing.*;
public class week2(B)
{
public static void main(String args[])
{
String n,l,m=" ";
int i,j,k;
int a[][]=new int[3][3];
int b[][]=new int[3][3];
int c[][]=new int[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
n=JOptionPane.showInputDialog(null,"enter elements of 1st matrix");
a[i][j]= Integer.parseInt(n);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
l=JOptionPane.showInputDialog(null,"enter elements of 2nd matrix");
b[i][j]= Integer.parseInt(l);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m=m+c[i][j];
}
m=m+"n";
JOptionPane.showMessageDialog(null,"resultant matrix is"+m);
}
}
}
Page 1