Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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_Loops_Sudoku_Drjava - Fatal编程技术网

Java解决方案检查器问题

Java解决方案检查器问题,java,loops,sudoku,drjava,Java,Loops,Sudoku,Drjava,我错过了这项任务的最后期限,但我不明白我在为这个项目做什么,这仍然困扰着我。它是数独解决方案检查器的第2部分,需要添加四种方法 public boolean checkAndPrintReport( ) {*/return true;} 它应该检查所有行并打印每个失败的行或列。其他的是 public boolean isGoodRow( int yRowParam ) {return true;} public boolean isGoodColumn( int xColParam ) {re

我错过了这项任务的最后期限,但我不明白我在为这个项目做什么,这仍然困扰着我。它是数独解决方案检查器的第2部分,需要添加四种方法

public boolean checkAndPrintReport( ) {*/return true;}
它应该检查所有行并打印每个失败的行或列。其他的是

public boolean isGoodRow( int yRowParam ) {return true;}
public boolean isGoodColumn( int xColParam ) {return true;}
public boolean isGoodBlock(int xBlockP, int yBlockP) {return true;} 
最后,我的checkAll()方法应该有三个嵌套循环,每个循环调用上述三个循环9次

我不明白这个部分需要什么,因为我认为我已经在这里编写了一个解决方案检查器

public int timesRowHas( int yParam, int number ) { 
    int nTimesHas = 0;
    for( int x = 0; x < 9; x++ )
        if( this.getCell(x, yParam) == number )
            nTimesHas = nTimesHas + 1;

    return( nTimesHas );
}

public int timesColHas( int xParam, int number ) {
    int nTimesHas = 0;
    for( int y = 0; y < 9; y++ )
        if( this.getCell(xParam, y) == number )
            nTimesHas = nTimesHas + 1;

    return( nTimesHas );
}

public int timesBlockHas( int xBlockParam, int yBlockParam, int number ) {
    if( xBlockParam < 0 || xBlockParam > 2 || yBlockParam < 0 || yBlockParam > 2 )
        throw new IllegalArgumentException("Bad xBlockParam or bad yBlockParam or both..");

    int nTimesHas = 0; 
    for (int x=0; x<3; x++)
        for (int y=0; y<3;y++)
            nTimesHas = nTimesHas +getCell(xBlockParam+x, yBlockParam+y);

    return(nTimesHas);
 }
public int timesRowHas(int-yParam,int-number){
int nTimesHas=0;
对于(int x=0;x<9;x++)
if(this.getCell(x,yParam)==number)
nTimesHas=nTimesHas+1;
返回(nTimesHas);
}
公共int-timesColHas(int-xParam,int-number){
int nTimesHas=0;
对于(int y=0;y<9;y++)
if(this.getCell(xParam,y)==number)
nTimesHas=nTimesHas+1;
返回(nTimesHas);
}
公共int-timesBlockHas(int-xBlockParam、int-yBlockParam、int-number){
如果(xBlockParam<0 | | xBlockParam>2 | | yBlockParam<0 | | yBlockParam>2)
抛出新的IllegalArgumentException(“坏xBlockParam或坏yBlockParam或两者兼而有之…”);
int nTimesHas=0;

对于(int x=0;x您编写的函数不是您所需要的函数。您的函数只检查一行(列或框)中单个数字的次数

要判断行(列或框)是否正确,您确实需要检查所有数字(1-9),而不仅仅是其中一个

但是,好消息是,您可以使用自己的函数实现所需的函数:

public boolean isGoodRow( int yRowParam ){
    // for number = 1,..,9, ensure the count is not > 1
    for(int i=1; i<=9; i++)
        if(timesRowHas(yRowParam, i) > 1)
            return false;
    return true;
}
public boolean isGoodRow( int yRowParam )
public boolean isGoodColumn( int xColParam )
public boolean isGoodBlock(int xBlockP, int yBlockP)
然后,您只需要使用它们来实现
checkAndPrintReport()

public boolean checkAndPrintReport(){

对于(int i=0;我不知道我在建议的函数中放了什么,但是,他们似乎在要求我在上面已经做了什么。好吧,你解释的方式现在更有意义了。Block函数也可以工作吗?checkAll supossed是否在不同的.java中调用其他方法?它将与你的Block函数一起工作如果这有助于你,请选择这个作为正确答案并投票,谢谢!我想OP是在问他已经编写的函数是否实现了他被要求编写的函数的目标,为什么/为什么不?
public boolean checkAndPrintReport(){ 
   for(int i=0; i<9; i++)
        if(!isGoodRow(i) || !isGoodColumn(i) || !isGoodBlock(i/3, i%3)
            return false;
   return true;
}