I am working on an assignment to produce sudoku in Java. I have been given 81 values in the form of a string [9] by [9] just as in Sudoku. I need to break this string into 9 arrays of 9 and convert the individual character into an integer.
e.g. I have the following :
public static String candidateSolution = "735684291628591347194327865213869574876245139459173682367412958981756423542938716";
I was thinking to do a for loop where every 9 values it copies it to a new array index.
I have managed to get this far to output an entire 9x9 array but no values are inside.
My array declaration
public static int rows = 9;
public static int columns = 9;
public static int[][] sudokuGrid = new int[rows][columns];
My conversion of string to array
public void convertToArray(String candidateSolution){
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
sudokuGrid[i][j] =
Character.getNumericValue(candidateSolution.charAt(i));
}
}
}
My current output is
[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], ect...