Skip to main content
add ...[0].length stuff
Source Link

You probably should reread the specifications. “Check if the first dimensions and the second dimensions of each 2-dim. array array are the same” means that you should check if first and second matrix lengths match; it does not mean to test doubMatrix1[i][j] == doubMatrix2[i][j]. If Also test sizes of doubMatrix1[0] and doubMatrix2[0]; ie besides testing doubMatrix1.length vs doubMatrix2.length, test doubMatrix1[0].length vs doubMatrix2[0].length. If the sizes don't match, then do your return tempArray = new double[0][0]; statement, or perhaps return new double[0][0];. That particular statement should be before, not inside, the nested for loops.

“Add each corresponding element in the parameter 2-dim. arrays and store the result” means to do something like your
tempArray[i][j] = doubMatrix1[i][j] + doubMatrix2[i][j]; statement. However, your code repeatedly reallocates tempArray[][], so tempArray[][] never has more than one element set in it. Allocate the array earlier in your program, perhaps after you know the sizes match.

You probably should reread the specifications. “Check if the first dimensions and the second dimensions of each 2-dim. array array are the same” means that you should check if first and second matrix lengths match; it does not mean to test doubMatrix1[i][j] == doubMatrix2[i][j]. If the sizes don't match, then do your return tempArray = new double[0][0]; statement, or perhaps return new double[0][0];. That particular statement should be before, not inside, the nested for loops.

“Add each corresponding element in the parameter 2-dim. arrays and store the result” means to do something like your
tempArray[i][j] = doubMatrix1[i][j] + doubMatrix2[i][j]; statement. However, your code repeatedly reallocates tempArray[][], so tempArray[][] never has more than one element set in it. Allocate the array earlier in your program, perhaps after you know the sizes match.

You probably should reread the specifications. “Check if the first dimensions and the second dimensions of each 2-dim. array array are the same” means that you should check if first and second matrix lengths match; it does not mean to test doubMatrix1[i][j] == doubMatrix2[i][j]. Also test sizes of doubMatrix1[0] and doubMatrix2[0]; ie besides testing doubMatrix1.length vs doubMatrix2.length, test doubMatrix1[0].length vs doubMatrix2[0].length. If the sizes don't match, then do your return tempArray = new double[0][0]; statement, or perhaps return new double[0][0];. That particular statement should be before, not inside, the nested for loops.

“Add each corresponding element in the parameter 2-dim. arrays and store the result” means to do something like your
tempArray[i][j] = doubMatrix1[i][j] + doubMatrix2[i][j]; statement. However, your code repeatedly reallocates tempArray[][], so tempArray[][] never has more than one element set in it. Allocate the array earlier in your program, perhaps after you know the sizes match.

Source Link

You probably should reread the specifications. “Check if the first dimensions and the second dimensions of each 2-dim. array array are the same” means that you should check if first and second matrix lengths match; it does not mean to test doubMatrix1[i][j] == doubMatrix2[i][j]. If the sizes don't match, then do your return tempArray = new double[0][0]; statement, or perhaps return new double[0][0];. That particular statement should be before, not inside, the nested for loops.

“Add each corresponding element in the parameter 2-dim. arrays and store the result” means to do something like your
tempArray[i][j] = doubMatrix1[i][j] + doubMatrix2[i][j]; statement. However, your code repeatedly reallocates tempArray[][], so tempArray[][] never has more than one element set in it. Allocate the array earlier in your program, perhaps after you know the sizes match.