方法isFilledAt()
返回true
如果该形状在给定的row/col
位置上具有填充块,并且如果该块为空,则该形状具有false
。如果位置超出范围,请提供带有信息性消息的FitItException
。我正在运行一个嵌套循环来获得位置,并且很难找出一个位置是否超出范围。可以帮忙吗?提前致谢!如何检查二维数组是否超出范围?
public class CreateShape {
private int height;
private int width;
private char dc;
private Rotation initialPos;
public CreateShape(int height, int width, char dc)
{
this.height = height;
this.width = width;
this.dc = dc;
initialPos = Rotation.CW0;
}
public boolean isFilledAt(int row, int col)
{
char[][] tempArray = new char[height][width];
for(int i = 0; i < tempArray.length; i++)
for(int j = 0; j < tempArray[i].length; j++)
{
if(row > tempArray.length || row < 0)
throw new FitItException("Out of Bounds!");
if(tempArray[row][col] == dc)
return true;
}
return false;
}
'isFilledAt'应该做什么?当然'tempArray'应该是一个实例变量,并且该方法应该测试其中的一个条目?目前'tempArray'是一个局部变量,所以你对它做出的改变都会丢失。 –