Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:47:54+00:00 2026-06-15T08:47:54+00:00

I’m having some problems with my Sudoku Solver that I need to make, what

  • 0

I’m having some problems with my Sudoku Solver that I need to make, what I am supposed to do is to create a program which checks to see if the inputted Sudoku puzzle is correct or not. I have the code which checks to see if each row, column, and “minibox” working. My only problem now is to print out the puzzle. This is what I have so far:

public String printGrid(int size, int[][] puzzle){
    double temp = Math.sqrt(size);

    for(int row = 0; row < size; row++){
        for(int column = 0; column < size; column++){
            System.out.print(puzzle[row][column]);

            if(column == temp - 1) {
                System.out.print("|");   
            }

            if(row == temp - 1){
                for(int i = 0; i < size; i++){
                    System.out.print("-\t");
                }
            }

            if(column == size - 1) {
                column = 0;
                row++;
            }
        }
    }
    return "Correct!";
}

As an example size will be 4 and the inputted sudoku will be:

 1 2 3 4
 4 3 2 1 
 3 4 1 2
 2 1 4 3

My output is to look like this:

 1 2 | 3 4
 4 3 | 2 1
 ----+----
 3 4 | 1 2
 2 1 | 4 3

My current code however gives an ArrayOutOfBounds error and outputs this:

 -  2-  -   -   -   1-  -   -   -   4|121|43

I’m completely lost in how to write this method to output, can anyone shed some light on this for me? (Also ignore the fact that all sudokus return “Correct!” I should be able to figure that out myself.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:47:55+00:00Added an answer on June 15, 2026 at 8:47 am

    You have at least 4 problems that I see right away:

    1. You don’t print a newline at the end of your outer (row) loop
    2. The if(row == temp - 1) loop should be in the outer loop only (you want to do it on it’s own row, not each time in the column
    3. column == temp-1 etc. will only work for the 2×2 case, it should be column > 0 && column % temp == 0
    4. Don’t ever ever modify a for loop variable inside the loop, that will confuse everything and usually cause ArrayIndexOutOfBoundsException, as happens here.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.