fork download
  1. import java.util.Scanner;
  2. class Test{
  3. public static void main(String[] args){
  4. Scanner input = new Scanner("1 - - | 4 5 6 | - - - "+
  5. "5 7 - | 1 3 b | 6 2 4 "+
  6. "4 9 6 | 8 7 2 | 1 5 3 "+
  7. "======+=======+====== "+
  8. "9 - - | - - - | 4 6 - "+
  9. "6 4 1 | 2 9 7 | 8 3 - "+
  10. "3 8 7 | 5 6 4 | 2 9 - "+
  11. "======+=======+====== "+
  12. "7 - - | - - - | 5 4 8 "+
  13. "8 r 4 | 9 1 5 | 3 7 2 "+
  14. "2 3 5 | 7 4 $ | 9 1 6");
  15.  
  16. createBoard(input);
  17. }
  18.  
  19. public static int [][] createBoard(Scanner input){
  20.  
  21. int[][] nSudokuBoard = new int[9][9];
  22.  
  23. for (int rows = 0; rows < 9; rows++){
  24.  
  25. for (int columns = 0; columns < 9; columns++){
  26.  
  27. if(input.hasNext()){
  28.  
  29. if(input.hasNextInt()){
  30. int number = input.nextInt();
  31. nSudokuBoard[rows][columns] = number;
  32. }//end if int
  33.  
  34. else if(input.hasNext("-")){
  35. input.next();
  36. nSudokuBoard[rows][columns] = 0;
  37. System.out.print("Hyphen Found \n");
  38. }//end if hyphen
  39.  
  40. else if(input.hasNext("\\|")){
  41. System.out.print("border found \n");
  42. input.next();
  43.  
  44. }// end if border
  45. else if(input.hasNext("======\\+=======\\+======")){
  46. System.out.print("equal row found \n");
  47. input.next();
  48. }// end if equal row
  49.  
  50. else {
  51. System.out.print("Invalid character detected at... \n Row: " + rows +" Column: " + columns +"\n");
  52. System.out.print("Invalid character(s) replaced with a '0'. \n" );
  53. input.next();
  54. }//end else
  55.  
  56. }//end reading file
  57. }//end column for loop
  58. }//end row for looop
  59. return nSudokuBoard;
  60. }//end of createBoard
  61. }
Success #stdin #stdout 0.12s 212864KB
stdin
Standard input is empty
stdout
Hyphen Found 
Hyphen Found 
border found 
border found 
Hyphen Found 
Hyphen Found 
Hyphen Found 
Hyphen Found 
border found 
Invalid character detected at... 
 Row: 1 Column: 8
Invalid character(s) replaced with a '0'. 
border found 
border found 
border found 
equal row found 
Hyphen Found 
Hyphen Found 
border found 
Hyphen Found 
Hyphen Found 
Hyphen Found 
border found 
Hyphen Found 
border found 
border found 
Hyphen Found 
border found 
border found 
Hyphen Found 
equal row found 
Hyphen Found 
Hyphen Found 
border found 
Hyphen Found 
Hyphen Found 
Hyphen Found 
border found 
Invalid character detected at... 
 Row: 8 Column: 8
Invalid character(s) replaced with a '0'.