-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatrixUserDefineDemo1.java
More file actions
76 lines (62 loc) · 2.32 KB
/
MatrixUserDefineDemo1.java
File metadata and controls
76 lines (62 loc) · 2.32 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package array_demo;
/**
* @author Md. Talal Wasim
* https://github.com/mdtalalwasim
*/
import java.util.Scanner;
public class MatrixUserDefineDemo1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Row number for Matrix: ");
//int[][] A = {{},{},{},{}};
int m,n;
m = input.nextInt();
System.out.println("Enter Column number for Matrix: ");
n = input.nextInt();
int[][] A = new int[m][n];
int[][] B = new int[m][n];
//getting the input for Matrix A:
System.out.println("Please Enter elements for Matrix A:");
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
System.out.printf("A[%d][%d]=",row,col);
A[row][col] = input.nextInt();
}
System.out.println();
}
//getting the input for Matrix B:
System.out.println("Please Enter elements for Matrix B:");
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
System.out.printf("B[%d][%d]=",row,col);
B[row][col] = input.nextInt();
}
System.out.println();
}
//printing Matrix A elements:
System.out.println("Matrix A: ");
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
System.out.print("\t"+A[row][col]);
}
System.out.println();
}
//printing Matrix A elements:
System.out.println("Matrix B: ");
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
System.out.print("\t"+B[row][col]);
}
System.out.println();
}
System.out.println("\n\n");
//Matrix A + Matrix B (A + B)is :
System.out.println("A + B : ");
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
System.out.print("\t"+(A[row][col]+B[row][col]) );
}
System.out.println();
}
}
}