我正在使用二维数组,我想查看最后一行中最小元素的“左上角”“顶部”和“右上角”的元素。我有一个有效的代码,但是它显示了行中每个元素的所有方向,而不仅仅是最小的一个。任何人都可以帮忙吗?这是我的代码:
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];
}
}
}
}