Java 如何在if语句中获得返回true的方法 public boolean occursInBox(int-digit,int[]box) { //完成此方法 如果(数字>0&&数字>9) { 对于(int行=0;行9)(或if(数字>=0和) if (occursInBox(digit, getBox(boxRow, boxCol)))
我希望if语句只在if语句中的方法为true,但它表示类型为不可比较的int[]]和Boolean时才执行。if语句中的方法采用第一个occursInBox方法,它应该能够接受布尔变量Java 如何在if语句中获得返回true的方法 public boolean occursInBox(int-digit,int[]box) { //完成此方法 如果(数字>0&&数字>9) { 对于(int行=0;行9)(或if(数字>=0和) if (occursInBox(digit, getBox(boxRow, boxCol))),java,Java,我希望if语句只在if语句中的方法为true,但它表示类型为不可比较的int[]]和Boolean时才执行。if语句中的方法采用第一个occursInBox方法,它应该能够接受布尔变量 public boolean occursInBox(int digit, int[][] box) { //complete this method if (digit > 0 && digit > 9) { for (int row = 0
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 (occursInBox(digit, getBox(boxRow, boxCol) == true))
甚至更好
if (occursInBox(digit, getBox(boxRow, boxCol)) == true)
整个方法也可以
返回ocursinbox(digit,getBox(boxRow/3,boxCol/3))代码>和if(数字>0和9)
可以替换为if(数字>9)
(或if(数字>=0和)
if (occursInBox(digit, getBox(boxRow, boxCol)))