-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrixaddition.java
55 lines (49 loc) · 1.07 KB
/
matrixaddition.java
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
/**
* title:addition of two matrix
* created by:austin**/
import java.util.Scanner;
public class matrixaddition {
public static void main(String[] args)
{
Scanner in= new Scanner(System.in);
int matrix1[][],row,column,matrix2[][],sum[][];
System.out.println("enter the order of matrix 1");
row=in.nextInt();
column=in.nextInt();
System.out.println("enter the elements of matrix 1");
matrix1=new int[row][column];
for(int i=0;i<row;i++)
{
for (int j=0;j<column;j++)
{
matrix1[i][j]=in.nextInt();
}
}
System.out.println("enter the elements of matrix 2");
matrix2=new int[row][column];
for(int i=0;i<row;i++)
{
for (int j=0;j<column;j++)
{
matrix2[i][j]=in.nextInt();
}
}
System.out.println("sum of matrix is");
sum=new int [row][column];
for(int i=0;i<row;i++)
{
for (int j=0;j<column;j++)
{
sum[i][j]=matrix1[i][j]+matrix2[i][j];
}
}
for(int i=0;i<row;i++)
{
for (int j=0;j<column;j++)
{
System.out.print(sum[i][j]);
System.out.print("\t");
}System.out.print("\n");
}
}
}