Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Java

Java

Scheduled Pinned Locked Moved Java
questionjava
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rhod Ann
    wrote on last edited by
    #1

    what the whole code of "Soduko" ? please answer this question :-O

    M A 2 Replies Last reply
    0
    • R Rhod Ann

      what the whole code of "Soduko" ? please answer this question :-O

      M Offline
      M Offline
      Marco Bertschi
      wrote on last edited by
      #2

      Rhod-Ann wrote:

      what the whole code of "Soduko" ?

      And what is your question? Do you want to know how you can solve a sudoku in your local newspaper? - This would be the wrong forum for this. If you want to make a Sudoku in Java, use this one[^]. Google. It really solves problems.

      cheers Marco Bertschi


      Software Developer & Founder SMGT Web-Portal CP Profile | Twitter | Facebook | SMGT Web-Portal


      FizzBuzz - Gary Wheeler

      1 Reply Last reply
      0
      • R Rhod Ann

        what the whole code of "Soduko" ? please answer this question :-O

        A Offline
        A Offline
        apvkt
        wrote on last edited by
        #3

        public class Solution { public static void main(String[] args) { Solution s = new Solution(); char[][] board = {{'.', '2', '6', '5', '.', '.', '.', '9', '.'}, {'5', '.', '.', '.', '7', '9', '.', '.', '4'}, {'3', '.', '.', '.', '1', '.', '.', '.', '.'}, {'6', '.', '.', '.', '.', '.', '8', '.', '7'}, {'.', '7', '5', '.', '2', '.', '.', '1', '.'}, {'.', '1', '.', '.', '.', '.', '4', '.', '.'}, {'.', '.', '.', '3', '.', '8', '9', '.', '2'}, {'7', '.', '.', '.', '6', '.', '.', '4', '.'}, {'.', '3', '.', '2', '.', '.', '1', '.', '.'}}; s.solver(board); } public boolean solver(char[][] board) { for (int r = 0; r < board.length; r++) { for (int c = 0; c < board[0].length; c++) { if (board[r][c] == '.') { for (int k = 1; k <= 9; k++) { board[r][c] = (char) ('0' + k); if (isValid(board, r, c) && solver(board)) { return true; } else { board[r][c] = '.'; } } return false; } } } return true; } public boolean isValid(char[][] board, int r, int c) { //check row boolean[] row = new boolean[9]; for (int i = 0; i < 9; i++) { if (board[r][i] >= '1' && board[r][i] <= '9') { if (row[board[r][i] - '1'] == false) { row[board[r][i] - '1'] = true; } else { return false; } } } //check column boolean[] col = new boolean[9]; for (int i = 0; i < 9; i++) { if (board[i][c] >= '1' && board[i][c] <= '9') { if (col[board[i][c] - '1'] == false) { col[board[i][c] - '1'] = true; } else { return false; } } } //check the 3*3 grid boolean[] grid = new boolean[9]; for (int i = (r / 3) * 3; i < (r / 3) * 3 + 3; i++) { for (int j = (c / 3) * 3; j < (c / 3) * 3 + 3; j++) { if (board[i][j] >= '1' && board[i][j] <= '9') { if (grid[board[i][j] - '1'] == false) { grid[board[i][j] - '1'] = true; } else { return false; } } } } retu

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups