检查Java矩阵中所有条目是否都已“填充”。

huangapple 未分类评论48阅读模式
英文:

checking if all the entries are "filled" in the matrix in java

问题

以下是翻译好的内容:

我有一个作业,我正在创建一个名为“allSet”的方法,它将放在SudokuGrid类中。该方法应返回true,如果所有的盒子都被填满,返回false,如果任何一个盒子还没有被填满/仍然为空。作业中还指定了一个空盒子对应于值为0。

这是类的样子;

public class SudokuGrid {
    private int[][] grid;
    
    /** 构造一个空的数独。 */
    public SudokuGrid () {...}
              
    /** 在盒子(row, col)中设置值value。
        假设所有参数的值在1到9之间。 */
    public void put(int row, int col, int value) {...}
              
    /** 清除盒子(row, col)中的值。
        假设所有参数的值在1到9之间。 */
    public void clear(int row, int col) {...}
              
    /** 返回盒子(row, col)中的值,如果盒子为空则返回零。
        假设所有参数的值在1到9之间。 */
    public int get(int row, int col) {...}
              
    /** 判断盒子(row, col)是否为空。
        假设所有参数的值在1到9之间。 */
    public boolean empty(int row, int col) {...} 
}

这是我目前想出来的代码;

public boolean allSet(int row, int col, int value) {
		grid[row][col] = value;
		if (value != 0) {
			return true;
		} else {
			return false;
		}

	} 

我得到的错误信息是;

__Tester__.java:57: 错误: 无法将类SudokuGrid中的方法allSet应用于给定类型;
System.out.println(sg.allSet());
                     ^
  需要: int,int,int
  找到: 无参数
  原因: 实际参数列表和形式参数列表的长度不同
1 error

我一直在谷歌上搜索,但无法理解这是什么意思...与参数有关,我没有传递任何参数吗?

提前感谢您的帮助!
保重。

英文:

I have an assignment where I'm creating a method "allSet" that will go in the class SudokuGrid. The method is supposed to return true if all of the boxes are filled and false if any of the boxes are yet to be filled/still empty. It is also given in the assignment that an empty box corresponds to the value of 0.

This is what the class looks like;

public class SudokuGrid {
    private int[][] grid;
    
    /** Constructd an empty sudoku. */
    public SudokuGrid () {...}
              
    /** Sets the value value in the box (row, col).
        All arguments are assumed to have a value between 1 and 9. */
    public void put(int row, int col, int value) {...}
              
    /** Clears the the box (row,col).
        All arguments are assumed to have a value between 1 and 9.  */
    public void clear(int row, int col) {...}
              
    /** Returns the value in the box (row,col), zero if the box is empty.
        All arguments are assumed to have a value between 1 and 9. */
    public int get(int row, int col) {...}
              
    /** Determines if the box (row, col) is empty.
        All arguments are assumed to have a value between 1 and 9. */
    public boolean empty(int row, int col) {...} 
}

This is what I've come up with so far;

public boolean allSet(int row, int col, int value) {
		grid[row][col] = value;
		if (value != 0) {
			return true;
		} else {
			return false;
		}

	} 

And the error message I get is;

__Tester__.java:57: error: method allSet in class SudokuGrid cannot be applied to given types;
System.out.println(sg.allSet());
                     ^
  required: int,int,int
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

I've been googling and can't understand what that means.. Something with the parameters and I'm not passing anything in?

Thanks for your help in advanced!
Take care.

huangapple
  • 本文由 发表于 2020年5月4日 22:08:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/61594191.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定