...

View Full Version : fidning highest value of a row in a 2D array



loln4p
09-26-2008, 06:46 AM
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

rangana
09-26-2008, 08:00 AM
Java is not Javascript (http://www.htmlgoodies.com/beyond/javascript/article.php/3470971).

mic2100
09-26-2008, 12:31 PM
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.

rnd me
09-27-2008, 08:35 AM
fastest way i know:


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum