code: public boolean isInBounds(int row, int col) {
          return row >= 0 && col >= 0 && row < mat.getNumRows() && col < mat.getNumCols();
      }
docs: Returns true of the specified matrix element is valid element inside this matrix.
  
  @param row Row index.
  @param col Column index.
  @return true if it is a valid element in the matrix.