Java Week2(B) Notepad

347 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
347
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Week2(B) Notepad

  1. 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

×