package q11053;
public class AdditionOfMatrix {
/**
* Computes the addition of the two given matrices if the sizes of the matrices are the same.
* Otherwise, returns null.
*
* @return the resultant matrix, null if addition is not possible
*/
public int[][] add(int[][] matrix1, int[][] matrix2) {
// Write the code
int row=matrix1.length,col=matrix1[0].length;
int row1=matrix2.length,col1=matrix1[0].length;
int sum[][] = new int[row][col];
for(int i = 0; i<row; i++){
for(int j = 0;j<col;j++){
if(matrix1[i][j] != matrix2[i][j]){
sum[i][j] = matrix1[i][j]+matrix2[i][j];
} else{
return null;
}
}
}
return sum;
}
}

