Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Max Element In Matrix

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    Thanks in advance


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Max Element In Matrix

    Can you post the code that shows what you have tried?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Max Element In Matrix

    Here

    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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Max Element In Matrix

    Have you tried to compile that code? It doesn't look like java.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Matrix Program
    By panzer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 30th, 2013, 06:15 AM
  2. Replies: 0
    Last Post: September 7th, 2013, 06:09 AM
  3. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM
  4. [SOLVED] String max out
    By lorider93p in forum Java Theory & Questions
    Replies: 7
    Last Post: March 2nd, 2012, 10:43 AM
  5. Multi-D array. daily max/min/avg, weekly max/min/avg, sum total (99% done)
    By TheWhopper858 in forum Collections and Generics
    Replies: 1
    Last Post: November 6th, 2011, 08:50 PM

Tags for this Thread