/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sudoku;

/**
 *
 * @author shmooel
 */
public class Sudoku {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      int[][] table = new int[9][9]; //creating a table of sudoku
      int numbering = 0;
      int temp;
      int checkRow = 0, checkColumn = 0;
      boolean bool;
      int row, column;
     /**/
      while (numbering < 81){
          bool = true;
          column = (int)(Math.random()*(0-9+1)+9);
          row = (int)(Math.random()*(0-9+1)+9);
          temp = (int)(Math.random()*(0-10+1)+10);
          for (int i =0;i<9 ;i++){ //check row
              if (table[row][i] == temp){
                  bool = false;
              }
          }
          for (int i =0;i<9 ;i++){//check column
              if (table[i][column] == temp){
                  bool = false;
              }
          }
          /*check blocks*/
          /*rows*/
          if (bool == true){
              if (row <3){
                  checkRow = 0;
              }
              else{
                  if(row>2 && row<6){
                      checkRow = 3;
                  }
                  else{
                  if(row>5){
                      checkRow = 6;
                  }
              }
              }  
          }
          /*rows*/
          /*columns*/
          if (bool == true){
              if (column <3){
                  checkColumn = 0;
              }
              else{
                  if(column>2 && column<6){
                      checkColumn = 3;
                  }
                  else{
                  if(column>5){
                      checkColumn = 6;
                  }
              }
              }  
          }
          /*columns*/
          
          /*check*/
          for (int i=checkRow;i<(checkRow+3);i++){
              for (int i2=checkColumn; i2<(checkColumn+3);i2++){
                  if (table[i][i2] == temp){
                      bool =false;
                  }
              }
          }
          if (bool == true){
              if(table[row][column] == 0){
                  numbering++;
              }
              table[row][column] = temp;
              
              /*print the sudoku*/
      for (int i = 0; i<9; i++){
          for (int i2 = 0; i2<9; i2++){
              System.out.print(table[i][i2]);
              if (i2 == 2 || i2 == 5){
                  System.out.print("|");
              }
          }
          if (i ==2 || i ==5){
              System.out.println("");
              System.out.println("-----------");
          }
          else{
              System.out.println("");
      }
      }
      System.out.println("-----------");
      System.out.println("");
      System.out.println("-----------");
      /*end of printing*/
          }
      }//while
      /**/
      
      
      
      
      /*print the sudoku*/
      for (int i = 0; i<9; i++){
          for (int i2 = 0; i2<9; i2++){
              System.out.print(table[i][i2]);
              if (i2 == 2 || i2 == 5){
                  System.out.print("|");
              }
          }
          if (i ==2 || i ==5){
              System.out.println("");
              System.out.println("-----------");
          }
          else{
              System.out.println("");
      }
      }
      /*end of printing*/
    }
}
