-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmat_add.java
More file actions
37 lines (34 loc) · 935 Bytes
/
Copy pathmat_add.java
File metadata and controls
37 lines (34 loc) · 935 Bytes
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
//Matrix Addition
import java.util.Scanner;
public class mat_add{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Enter number of rows: ");
int row=input.nextInt();
System.out.print("Enter number of colums: ");
int cols=input.nextInt();
System.out.println("ENTER FIRST MATRIX: ");
int[][] mat1=new int[row][cols];
for(int i=0;i<row;i++){
for(int j=0;j<cols;j++){
mat1[i][j]=input.nextInt();
}
}
System.out.println("ENTER SECOND MATRIX: ");
int[][] mat2=new int[row][cols];
for(int i=0;i<row;i++){
for(int j=0;j<cols;j++){
mat2[i][j]=input.nextInt();
}
}
int result[][]=new int[row][cols];
System.out.println("Matrix Addition");
for(int i=0;i<row;i++){
for(int j=0;j<cols;j++){
result[i][j]=mat1[i][j]+mat2[i][j];
System.out.print(result[i][j]);
}
System.out.println();
}
}
}