I'm currently making a Sudoku using java, however i can't seem to figure out how to loop my scanner properly. So far it prints this:
. 1 . | 3 . . | 8 . .
5 . 9 | 6 . . | 7 . .
7 . 4 | . 9 5 | . 2 .
----------------------
4 . . | . . . | 1 . .
. 2 8 | . 7 1 | . 6 3
. . . | 2 . 4 | 9 5 .
----------------------
6 . 3 | . . 9 | . . 7
. . . | 4 2 . | 5 1 6
. 5 2 | . 8 . | . 4 .
Next move, please (row , column , value )
And i'm able to change the chars '.' whith my code, but i want to loop that properly. So if the sudoku still contains the char '.', i want it to loop the scanner to edit it once more. I'm still fairly new to scripting
And this is the code i have made to edit it so far:
public void moves(int row , int column , int value) {
value += 48;
if (list.get(row).charAt(column) == '.'){
StringBuilder sb = new StringBuilder(list.get(row));
sb.setCharAt(column, (char)value);
list.set(row, sb.toString());
}
}
public static void main(String[] args) throws Exception {
Sudoku s = new Sudoku("C:\\Users\\caspe\\Downloads\\Sudoku001.sdk");
s.printBoard();
s.errorCheck();
System.out.println("Next move, please (row , column , value )");
Scanner scanner = new Scanner(System.in);
int row = scanner.nextInt();
int column = scanner.nextInt() ;
int value = scanner.nextInt();
s.moves(row, column, value);
s.errorCheck();
s.printBoard();
}
}
So to sum it up, how can i loop the scanner until there are no more dots/'.'?