MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / add

Method add

Lecture 20 - 2D Arrays/src/Matrix.java:37–52  ·  view source on GitHub ↗
(int[][] a, int r1, int c1, int[][] b, int r2, int c2)

Source from the content-addressed store, hash-verified

35 }
36
37 static void add(int[][] a, int r1, int c1, int[][] b, int r2, int c2){
38 if(r1 != r2 || c1 != c2){
39 System.out.println("Wrong Input - Addition not possible");
40 return;
41 }
42
43 int[][] sum = new int[r1][c1];
44
45 for(int i = 0; i < r1; i++){ //row number
46 for(int j = 0; j < c1; j++){ //column number
47 sum[i][j] = a[i][j] + b[i][j];
48 }
49 }
50 System.out.println("Sum of matrix 1 and matrix 2");
51 printMatrix(sum);
52 }
53
54 public static void main(String[] args) {
55 Scanner sc = new Scanner(System.in);

Callers 2

mainMethod · 0.45
mainMethod · 0.45

Calls 1

printMatrixMethod · 0.95

Tested by

no test coverage detected