-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