# Max Element In Matrix

• December 6th, 2013, 06:32 PM
shirayukilee
Max Element In Matrix
Hello

I am beginner in programming and I need a little help. In given matrix, I have to find elements that are maximal for its row and column.

For example in matrix

5 7 3 4 8
4 5 9 4 6
3 10 6 7 5
6 4 8 1 9

program should check first row (5 7 3 4 8) and second column (7 5 10 4) and return 10. After that it should continue search and for e.g second row (4 5 9 4 6) and third column (3 9 6 1) return 9. And so on...

I know how to find max for whole matrix, but I need to find (multiple) max(es) for every row and column together.

If there's any question, I'll try to answer

• December 6th, 2013, 06:54 PM
Norm
Re: Max Element In Matrix
Can you post the code that shows what you have tried?
• December 6th, 2013, 07:07 PM
shirayukilee
Re: Max Element In Matrix
Here

Code :

```for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i, j] > max) { max = a[i, j]; } } } label1 = new JLabel(max);```

I think I am close to solution, but I am not quite sure how to do this exactly.
• December 6th, 2013, 07:22 PM
Norm
Re: Max Element In Matrix
Have you tried to compile that code? It doesn't look like java.