This class sums a 2D matrix.
To use this class, just make a simple object of
Find2DMatrixSum
class and callfindSumOfMatrix()
method which returns you anint
which represents the sum of the matrix. If the sum can exceed theint
range, you can usefindLongSumOfMatrix()
to get thelong
number as sum.
public int findSumOfMatrix() {
// returns sum of matrix
}
public int findLongSumOfMatrix() {
// returns long sum of matrix
}
Example code, for understanding:
public static void main(String[] args){
int[][] arr = new int[][]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
Find2DMatrixSum mSum = new Find2DMatrixSum(arr);
System.out.println(mSum.findSumOfMatrix()); // 45
}