# Minimum of 2d Array

• 03-10-2011, 03:56 PM
Spyderpig
Minimum of 2d Array
trying to get the minmum of a 2d array... not sure what im doing wrong.

Code:

```        int[][] toReverse = {                         {11,5,5,5,5},                         {3,7,8,9,10},                         {1,2,3,4,5},                         {1,2,3,4,5},                         {1,2,3,4,5}                         };                 int min = toReverse[0][0];         for (int i=0; i<toReverse.length;i++){                 for(int k=1;k<toReverse.length;k++){                 if(toReverse[i][k]<min)                         min=toReverse[i][k];                 }         }         System.out.print(min);```
• 03-10-2011, 04:20 PM
doWhile
Quote:

not sure what im doing wrong
And neither are we, unless you provide a more detailed description of the problem. Does it compile? Are there exceptions? Does it behave properly?
• 03-10-2011, 04:22 PM
KevinWorkman
Why are you starting k at 1?
• 03-10-2011, 04:27 PM
Spyderpig
starting at k=1 because i set the min to [0][0] already, which im not sure is right. anyways im trying to get the minimum value of the array which should be 1 but the output is 2.
• 03-10-2011, 04:39 PM
KevinWorkman
Hint- Draw a 2D array, and label the "coordinates" of each index. For example, the coordinates of the index holding the number 10 is [1][4].
• 03-10-2011, 04:50 PM
Spyderpig
yea i know how coordinates of arrays work. that doesnt help at all...
• 03-10-2011, 04:58 PM
KevinWorkman
Quote:

Originally Posted by Spyderpig
yea i know how coordinates of arrays work. that doesnt help at all...

Sorry, but if you knew how arrays worked, you wouldn't be having this issue. But if you're unwilling to try some simple advice, I'm not going to waste my time.

Much luck.
• 03-10-2011, 05:02 PM
Spyderpig
advice helps people. what you said is the equivalent of saying the world is round. we all know this. thanks for failing.
• 03-10-2011, 05:05 PM
KevinWorkman
Quote:

Originally Posted by Spyderpig
advice helps people. what you said is the equivalent of saying the world is round. we all know this. thanks for failing.

Failing? I'm not the one who can't figure out basic arrays. /immature

I was perfectly willing to offer you some more hints, had you tried my first one and still not understood what I was getting at. I still think you'd figure it out if you followed my advice.

Don't worry, I'm sure somebody will eventually come around and spoonfeed you your blatant error. But your terrible attitude and apparent laziness pretty much guarantee a short career in programming.