public boolean occursInBox(int digit, int[][] box)
{
//complete this method
if (digit > 0 && digit > 9)
{
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
if(box[row][col] == digit)
{
return true;
}
}
}
}
return false;
}
public boolean occursInBox(int digit, int row, int column)
{
//complete this method
int boxRow = (row/3);
int boxCol = (column/3);
if (occursInBox(digit, getBox(boxRow, boxCol) == true))
{
return true;
}
return false;
}
我希望if语句只有在if语句中放入的方法为true但它表示类型是无比的int [] []和Boolean时才能通过。 if语句中的方法采用第一个happenInBox方法,它应该能够接受布尔变量
答案 0 :(得分:3)
if (occursInBox(digit, getBox(boxRow, boxCol) == true))
应该是
if (occursInBox(digit, getBox(boxRow, boxCol)) == true)
甚至更好
if (occursInBox(digit, getBox(boxRow, boxCol)))