Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with Sudoku function please

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Sudoku function please

    Hi, I am trying to write a function that takes as input a double array [9][9] of integers (like a Sudoku board) and checks to see if every cluster of 9 squares is correct, meaning that no number is repeated. I am basically going through the cluster, putting the values into a temporary array (temp[]) and looping through temp[] to see if any number is repeated. I think my code is correct, but I am getting a "cannot find symbol, symbol: variable k". I am sure it is something really simple, but I've been working on this for over an hour and my eyes are just missing it. I'm sure someone can spot it right away.

    Here is the function I've been working on:


    public boolean checkClusters(int[][] board) {
     
          int[] temp = new int[9];
          int counter = 0;
          int error = 0;
     
          search:
            for (int i = 0; i < 9; i += 3) {
            for (int j = 0; j < 9; j += 3) {
     
              for (int ii = 0; ii < 3; ii++) {
                for (int jj = 0; jj < 3; jj++) {
     
                  if (ii == 0)
                    temp[ii + jj] = board[i + ii][j + jj];
                  else if (ii == 1)
                    temp[2 + ii + jj] = board[i + ii][j + jj];
                  else if (ii == 2)
                    temp[4 + ii + jj] = board[i + ii][j + jj];
     
                  for (int k = 0; k < 9; k++)
                    for (int kk = 0; kk < k % 9; kk++)
                      if (temp[k] == 0)
                        break;
                      if (temp[k] == temp[kk]) {
                        error = 1;
                        break search;
                      }
                }
              }
            }
          }
            return error == 0;
        }


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Sudoku function please

    bump, bump

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: Help with Sudoku function please

    First of all, you don't need to bump your posts. Bumping it won't get you help any faster.

    Second, you should probably align all your braces along with each other since you have a bunch of nested for loops.

Similar Threads

  1. Sudoku Creator (this could be a long one)
    By aussiemcgr in forum Java Theory & Questions
    Replies: 8
    Last Post: July 27th, 2010, 01:19 PM
  2. Sudoku solver
    By Elliott50 in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 22nd, 2009, 02:03 PM
  3. Sudoku coding help...please
    By sketch_flygirl in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 5th, 2009, 10:07 PM
  4. Sudoku
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2009, 10:09 PM
  5. Sudoku Solver
    By MysticDeath in forum Java Theory & Questions
    Replies: 5
    Last Post: September 19th, 2009, 10:33 PM