I am working with a 2D array and I would like to view the elements to the "top left" "top" and "top right" of the smallest element in the last row. I have a code that works however it displays all of the directions of every element in the row, not just the smallest one. Can anyone help? This is my code:
for (int y = array.length-1; y == array.length-1; y--)
{
for (int x = 0; x < array[y].length; x++)
{
int lowest = array[y][0];
for (x = 0; x < array[y].length; x++)
{
if (array[y][x] <= lowest)
lowest = array[y][x];
//if element is on left
if (x == 0)
{
up = array[y-1][x];
upRight = array[y-1][x+1];
upLeft = 0;
}
//if element is on right
else if (x == array[0].length - 1)
{
upLeft = array[y-1][x-1];
up = array[y-1][x];
upRight = 0;
}
//if element is anywhere else
else
{
upLeft = array[y-1][x-1];
up = array[y-1][x];
upRight = array[y-1][x+1];
}
}
}
}