-2
我不能手动测试我的方法的代码,因为我还没有完成其他相关的代码,但我觉得方法public boolean isFilledAt(int row, int col)
的逻辑是错误的。如果该形状在给定的行/列位置具有填充的块(任何char
),并且如果该块为空(点'.'
),则返回true
false
。如果位置超出范围,请提供带有信息性消息的FitItException
。请问请看看它,让我知道如果方法的代码有什么问题?谢谢!不确定代码的逻辑
public class CreateShape {
private int height;
private int width;
private char dc;
private Rotation initialPos;
private char[][] shape = new char[height][width];
public boolean isFilledAt(int row, int col)
{
if(row < 0 || row >= height || col < 0 || col >= width)
throw new FitItException("Oops! Out of bounds!");
else
{
for (int i = 0; i < shape.length; i++)
for (int j = 0; j < shape[i].length; j++) {
if (shape[row][col] == dc)
return true;
}
}
return false;
}
你需要迭代吗? –
:) :),简直想不到! @PrashantGhimire谢谢,我现在要改变它! – Nikolay