-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTwoMatrix.java
More file actions
47 lines (32 loc) · 1.18 KB
/
AddTwoMatrix.java
File metadata and controls
47 lines (32 loc) · 1.18 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
package AllDailyPractice;
import java.util.Scanner;
public class AddTwoMatrix {
public static void main(String[] args) {
int m, n, i, j;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = sc.nextInt();
n = sc.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
first[i][j] = sc.nextInt();
System.out.println("Enter the elements of second matrix");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
second[i][j] = sc.nextInt();
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
sum[i][j] = first[i][j] + second[i][j];
System.out.println("Sum of entered matrices:-");
for ( i = 0 ; i < m ; i++ )
{
for ( j = 0 ; j < n ; j++ )
System.out.print(sum[i][j]+"\t");
System.out.println();
}
}
}