2 Replies Latest reply: May 11, 2007 10:37 AM by 569573

# Method for finding the smallest value of a 2d array

so far i have
`````` public static void RowSumMin (int[][] table, int rows)
{
int sum[] = new int[rows];
int region=0;
/**for (int row=0; row < table.length; row++)
{
sum [row] = 0;
for (int col=0; col < table[row].length; col++)
sum [row] = sum [row] + table[row][col];
}
*/
int min = my_2D_Methods.min2DSearch(table);

for(int x=0; x < sum.length; x++)
{
if (min == sum[x])
region = x+1;
}

System.out.println("The worst annual revenue is \$" + min + " in region " + region);

}``````
and
``````public static int min2DSearch(int a[][])
{
int min = a[0][0];

for (int index=0; index < a.length; index++)
{
for (int index2=0; index2 < a.length; index2++)
if(min > a[index][index2])
min = a[index][index2];

}
return min;
}``````
but its not working, any ideas?
• ###### 1. Re: Method for finding the smallest value of a 2d array
Ideas:

1: Define "not working".

2: Fix this line so that you can deal with non-square arrays (arrays for which first dimension is not equal to second dimension):
``for (int index2=0; index2 < a.length; index2++)``
• ###### 2. Re: Method for finding the smallest value of a 2d array
Some reference for you
http://www.leepoint.net/notes-java/data/arrays/arrays-2D-2.html