Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fidning highest value of a row in a 2D array

    okey, when I have an 2D array like

    new double[11][17]
    and I insert several values

    How can I extract the row from the array with the highest value total?

    Yes I am a programmernEWB_bbBB

    // peace

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    y not create a lil `if` statement below the code the use to insert the new value to the array. this would only check whether or not this value is greater than any of the previous entries. I am not sure how you do this in Java but im sure it wouldn't be to difficult.

    In php there are functions to sort array values and i would think that Java would have similar function.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,302
    Thanks
    10
    Thanked 586 Times in 567 Posts
    fastest way i know:
    Code:
    var r = [
       [1,2,3,4,5],
       [5,22,43,51,14,25],
       [121,2,3,4,5] 
    ];
    
    Math.max.apply(1, r[0])   //==5
    Math.max.apply(1, r[1])   //==51
    Math.max.apply(1, r[2])   //==121
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •