I currently need to add all the rows up in an array using only absolute values and then finding the maximum value out ot the three answers.
This is what I currently got:
public static int maxRowAbsSum(int[][] array) {
int[][] maxRowValue = {
{3, -1, 4, 0},
{5, 9, -2, 6},
{5, 3, 7, -8}
};
int maxRow = 0;
int indexofMaxRow = 0;
for (int column = 0; column < maxRowValue[0].length; column++) {
maxRow += maxRowValue[0][column];
}
for (int row = 1; row < maxRowValue.length; row++) {
int totalOfRow = 0;
for (int column = 0; column < maxRowValue[row].length; column++){
totalOfRow += maxRowValue[row][column];
if (totalOfRow > maxRow) {
maxRow = totalOfRow;
indexofMaxRow = row;
}
}
System.out.println("Row " + indexofMaxRow + " has the sum of " + maxRow);
}
return indexofMaxRow;
}
But this only returns the index row 1 total without using absolute values.
UPDATE: How would I write the JUnit code to test this using assertArrayEquals?