plz fix this error /** * setting and element to row r and column c with value v
ID: 3875693 • Letter: P
Question
plz fix this error
/**
* setting and element to row r and column c with value v
* The method must check that r and c are in the range of numberOfRow() and numberOfColumn().
* It should not do anything if r or c is out of range of the dimension of the matrix
* @param r
* @param c
* @param v
*/
public void set(int r, int c, double v)
{
int numberOfRow = r;
int numberOfColumn = c;
double[][] matrix = new double[r][c];
if(r>=numberOfRow && c >=numberOfColumn)
matrix[r][c] = v;//to be completed
}
Explanation / Answer
/**
* setting and element to row r and column c with value v The method must
* check that r and c are in the range of numberOfRow() and
* numberOfColumn(). It should not do anything if r or c is out of range of
* the dimension of the matrix
*
* @param r
* @param c
* @param v
*/
public void set(int r, int c, double v) {
int numberOfRow = r;
int numberOfColumn = c;
// here defining the matrix with row size r and column c,
double[][] matrix = new double[r][c];
if (r >= numberOfRow && c >= numberOfColumn)
// cannot allocate the size with r and c, raises indexoutofbounds
matrix[r - 1][c - 1] = v;// to be completed
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.