forked from ikismail/JavaBasicPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray8.java
More file actions
61 lines (52 loc) · 1.33 KB
/
Array8.java
File metadata and controls
61 lines (52 loc) · 1.33 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
package Day3;
import java.util.Scanner;
public class Array8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number of Rows");
int row = sc.nextInt();
System.out.println("Enter Number of Columns");
int col = sc.nextInt();
int[][] m1 = new int[row][col];
int[][] m2 = new int[row][col];
int[][] m3 = new int[row][col];
System.out.println("Enter the values");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
m1[i][j] = sc.nextInt();
}
}
System.out.println("First Matrix");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.print(m1[i][j]+" ");
}
System.out.println();
}
System.out.println("Enter the values");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
m2[i][j] = sc.nextInt();
}
}
System.out.println("Second Matrix");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.print(m2[i][j]+" ");
}
System.out.println();
}
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
m3[i][j] = m1[i][j] + m2[i][j];
}
}
System.out.println("Addition of 2 Matrix");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.print(m3[i][j] +" ");
}
System.out.println();
}
}
}