我創建了一個sodoku檢查器。這是我迄今爲止所做的,但我有點碰壁。在我的檢查器中,我不允許將方法中的一個從int更改爲布爾值,這對我來說很困難。java中的數獨檢查器幫助需要從布爾型切換到int
public class SudokuVerifier {
public static int[][] candidateSolution()
{
Scanner input = new Scanner(System.in);
int [][] sudokuboard = new int [9][9];
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
sudokuboard[i][j] = input.nextInt();
input.close();
return sudokuboard;
}
public int verify(String candidateSolution)
//checking rows
{
for (int i = 0; i < sudokuboard.length; i++)
if (validcheck(sudokuboard[i]))
return 1;
}
/**
* Tells the candidate to enter their sodoku puzzle
* it then gets stored into a 2 dimensional array
* array gets returned
* tells them if it's right or wrong
* @author sultan
*
*/
public static void main(String[] args)
{
int [][] sudokuboard = candidateSolution();
System.out.print(solutionChecker(sudokuboard) ? "right solution" : "Wrong solution");
}
public static boolean solutionChecker(int [][] sudokuboard)
{
return true;
}}
「公共INT驗證」是我無法改變的一部分,它給我的錯誤。所以我想知道是否有一種方法來保持這段代碼差不多相同,但使用整數我的返回而不是布爾值來計算行,列和3X3板。有人可以請幫助,我卡住了
所以你要使用方法返回的int,而不是布爾,只是使該方法返回1或0(TRUE或FALSE)。 – prsvr
或返回未通過有效性檢查的字段數量,其中0表示「無錯誤」==「已解決」。 – daniu