Solved

# Find minimum and maximum value for two dimensional array

Posted on 2010-11-10

Hi, I have been beating my head against the wall trying to figure this out. I am trying to figure out the minimum and maximum value for a single row. I have added the values from three rows of a two dimensional array into a fourth row and I want to get the minimum and maximum value from the row but I can't seem to figure it out. The code below gives me weird results. I set my min and max at [3][0] because I only want to scan row 3. Thanks for the help.

int min = sales[3][0];

for (int row = 3; row < sales.length; row++)

{

for (int column = 0; column < grades.length; column++)

{

if (sales[row][column] < min)

min = sales[row][column];

}

}

//Maximum

int max = grades[3][0];

for (int row = 0; row < sales.length; row++)

{

for (int column = 0; column < sales.length; column++)

{

if (sales[row][column] > max)

max = sales[row][column];

}

}