Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 数独棋盘_Java_Sudoku_Solver - Fatal编程技术网

Java 数独棋盘

Java 数独棋盘,java,sudoku,solver,Java,Sudoku,Solver,我有一个关于我正在编写的代码的问题。我需要创建一个数独棋盘检查器。目标是通过使用5个特定的方法来扩展数独类(使之成为可检查的数独类),我必须使用public boolean checkAll()来检查所有的方法,如果通过,则返回true。这是我的密码!对不起,我解释得太混乱了:/ import java.util.Scanner; public class CheckableSudoku extends Sudoku { public int getCell(int xColumn, i

我有一个关于我正在编写的代码的问题。我需要创建一个数独棋盘检查器。目标是通过使用5个特定的方法来扩展数独类(使之成为可检查的数独类),我必须使用public boolean checkAll()来检查所有的方法,如果通过,则返回true。这是我的密码!对不起,我解释得太混乱了:/

import java.util.Scanner;
public class CheckableSudoku extends Sudoku
{
    public int getCell(int xColumn, int yRow)
    {
        return this.board[xColumn][yRow];
    }

    public boolean checkRow (int yCoord)
    {
        int sum = 0;

        for ( int x = 0; x <9; x++)
        {
            sum = sum + getCell (x,yCoord);
        }
    return( true );
    }

    public boolean checkColumn (int xCoord)
    {
        int sum = 0;
        for (int y = 0; y < 9 ;y++)
        {
            sum = sum + getCell (xCoord, y);
        }
        return( true );
    }

    public boolean checkBlock (int col0to2, int row0to2)
    {
        int sum = 0;
        for (int x=0; x<3; x++)
        {
            for (int y=0; y<3;y++)
            {
                sum = sum + getCell (col0to2+x, row0to2+y);
            }
        }
        return( true);
    }

    public boolean checkAll()
    {
    // this is the method that checks all the other methods above
    return true;
    }

    public static void main(String[] a)
    {
        CheckableSudoku me = new CheckableSudoku();
        Scanner sc = new Scanner(System.in);
        me.read(sc);
        System.out.print(me);

        System.out.println(me.checkAll());
    }
}
import java.util.Scanner;
公共类可检查数独扩展了数独
{
公共int getCell(int xColumn,int yRow)
{
返回此.board[xColumn][yRow];
}
公共布尔校验行(int yCoord)
{
整数和=0;

对于(int x=0;x,这里有一个示例,说明如何检查它们是否都返回真值:

public boolean checkAll() {
    return (method1() && method2() && method3() && method4() && method5());
}
或:


到目前为止,您的所有方法似乎都返回了真值。不确定这是否只是一个示例。如果不是,您需要检查您的逻辑。

具体来说,您的问题是什么?您的问题是什么?
// Same thing but more typing.
public boolean checkAll() {
    if (method1() && method2() && method3() && method4() && method5())
         return true;
    else 
         return false;
}