I want to find the max element of row's by checking row by row and the same for columns!
Example 2D Array:
3 7 2
5 1 4
6 9 8
By checking every row element by element it should go like this: on the first row 7 is max, then on the second row there's no element greater than 7 so max is still 7, then on the third row 9 is greater than 7 so max element of rows is 9!
Then the same for columns: 6 is max on the first column, then on the second column 9 is max and on the third column there's no element greater then 9, therefore max of columns is 9!
By theory the max element of rows is also the max element of columns!
So, I need to make a Java program that does that so the result of max rows and max columns will be equal, which means that my program runs correctly!
On my code I have stored my 2D Array on bigMatrix[][], but I don't understand how is it possible to take the whole row with bigMatrix[i], it works but I don't understand how, and I don't know how to do the same to take every column and pass them as array to my function getMax() to find the max of that column!
**The below code works fine for finding the max element of Rows, but I don't know how to find the max element of Columns!
int rowMax = Integer.MIN_VALUE;
for(int i = 0; i < 3; i++) {
if(rowMax < getMax(bigMatrix[i])) {
rowMax = getMax(bigMatrix[i]);
}
}
public static int getMax(int[] ourArray) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < ourArray.length; i++) {
max = Math.max(max, ourArray[i]);
}
return max;
}
n*nmatrix? i.e, row count is equal to column count?