ection Part ock. Lxamples are given for clarity only; write code that witl 2 Cod
ID: 3874483 • Letter: E
Question
ection Part ock. Lxamples are given for clarity only; write code that witl 2 Code Writing Write code to accvanplish the goal stated in the opper bl ters tand not onb the cxamplest. This probdem is worth 18 points et resuit for any valid values of the input parame array where each element is the maximum the at the inpat 2D aray an array below m varue or the corresponding row of the input zD array. You can assume u 1 rovw and at least I cotumn. For exampie, rerurn (9.7. ., a.8) for the a row,7 coi 4.3 8 74.5 .28.4.1 4.7 a.6 blic doublExplanation / Answer
Programming language is not specified. Since the words public and double[] are visible, I am assuming it is Java. The question is not fully visible. The function name , parameter names are not visible. So using name as rowMax for function name.
public double[] rowMax(double[][] num)
{
int rows = num.length;
int cols = num[0].length;
double[] result = new double[rows];
for(int i = 0; i < rows; i++)
{
result[i] = num[i][0]; //assume 1st element in the row is maximum
for(int j = 1; j < cols; j++)
{
if(num[i][j] > result[i])
result[i] = num[i][j];
}
}
return result;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.