public void printSumOfAllRectangleMatrix(int input[][]){
        for(int rlen = 1 ; rlen <= input.length; rlen++){
            for(int clen = 1; clen <= input[0].length; clen++){
                for(int i=0; i < input.length - rlen + 1; i++){
                    for(int j=0; j < input[i].length - clen + 1; j++){
                        int sum = 0;
                        for(int k=i;k < i+rlen; k++){
                            for(int m = j; m < j+clen; m++){
                                sum += input[k][m];
                            }
                        }
                        System.out.println("Start " + i + " " + j + " End " + (i + rlen-1) + " "  + (j + clen-1) + " sum " + sum);
                    }
                }
            }
        }
    }
Iterate through matrix and get all subsquare and subrectangle matrix and print their sum
src/com/interview/multiarray/MatrixFindAllSubSquareRectangleMatrix.java