-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd_SquareMatrices.java
More file actions
62 lines (51 loc) · 1.21 KB
/
Copy pathAdd_SquareMatrices.java
File metadata and controls
62 lines (51 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Examples;
import java.util.Scanner;
public class Add_SquareMatrices {
public static void main(String args[])
{
int i,j;
int add[][] = new int[3][3];
int a[ ][ ] = new int[3][3];
int b[ ][ ] = new int[3][3];
Scanner sc = new Scanner(System.in);
System.out.println("Enter first 3X3 matrix is :");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
a[i][j] = sc.nextInt();
}
System.out.println("Enter second 3X3 matrix is :");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
b[i][j] = sc.nextInt();
}
System.out.println("\nThe first 3X3 matrix is : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
System.out.print(a[i][j]+"\t");
System.out.println(" ");
}
System.out.println("\nThe second 3X3 matrix is : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
System.out.print(b[i][j]+"\t");
System.out.println(" ");
}
System.out.println(" ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
add[i][j] = a[i][j] + b[i][j];
}
System.out.println("The resultant addition 3X3 matrix is :") ;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
System.out.print(add[i][j]+"\t");
System.out.println(" ");
}
}
}