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 8853903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:45:37+00:00 2026-06-14T13:45:37+00:00

I have somewhat of a strange problem. I’m writing a simple Sudoku program. Everything

  • 0

I have somewhat of a strange problem.

I’m writing a simple Sudoku program. Everything works perfectly now except this method:

public static void checkAnswerKey()
    {
        int rowCounter = 0;
        int columnCounter = 0;

        System.out.println("The answers that are correct are (F is incorrect): ");

        for (rowCounter = 0; rowCounter <= 8; rowCounter += 1)
        {
            for (columnCounter = 0; columnCounter <= 8; columnCounter += 1)
            {
                if (gui.userInputFormattedArray[rowCounter][columnCounter].getText() == io.puzzleAnswerArray[rowCounter][columnCounter].toString())
                {
                    gui.userInputFormattedArray[rowCounter][columnCounter].setBackground(gui.correctAnswer);
                    System.out.print(gui.userInputFormattedArray[rowCounter][columnCounter].getText() + " ");
                }
                else
                {
                    gui.userInputFormattedArray[rowCounter][columnCounter].setBackground(gui.incorrectAnswer);
                    System.out.print(gui.userInputFormattedArray[rowCounter][columnCounter].getText() + io.puzzleAnswerArray[rowCounter][columnCounter].toString() + " ");
                    //System.out.print("F" + " ");
                }
            }
            System.out.println();
        }

This is taken from the game.java file.

Now, this method is supposed to check the user input against the internal answer. Which it does. But everything turns up incorrect.

Here are the declarations/instantiations from the io.java and the gui.java files.

public class gui extends JFrame implements ActionListener{

…

    public static JFormattedTextField[][] userInputFormattedArray = new JFormattedTextField[9][9];
    //Create the container.
    public Container pane = getContentPane();
    //The font the game uses.
    public Font gameFont = new Font("Arial", Font.PLAIN, 30);
    //Correct and incorrect answer colors.
    static Color correctAnswer = new Color(100, 255, 100);
    static Color incorrectAnswer = new Color(255, 100, 100);

These two methods are launched in the constructor:

public void showTextFields()
    {
        int rowCounter = 0;
        int columnCounter = 0;

        for (rowCounter = 0; rowCounter <= 8; rowCounter += 1)
        {
            for (columnCounter = 0; columnCounter <= 8; columnCounter += 1)
            {
                userInputFormattedArray[rowCounter][columnCounter] = new JFormattedTextField();
                pane.add(userInputFormattedArray[rowCounter][columnCounter]);
                userInputFormattedArray[rowCounter][columnCounter].setFont(gameFont);
                userInputFormattedArray[rowCounter][columnCounter].setHorizontalAlignment(JTextField.CENTER);
            }
        }
    }

    public void setTextFields()
    {
        String heldString;
        boolean notEditable = false;
        int rowCounter = 0;
        int columnCounter = 0;

        for (rowCounter = 0; rowCounter <= 8; rowCounter += 1)
        {
            for (columnCounter = 0; columnCounter <= 8; columnCounter += 1)
            {
                if (game.puzzleUserShownArray[rowCounter][columnCounter] != 0)
                {
                    heldString = game.puzzleUserShownArray[rowCounter][columnCounter].toString();
                    userInputFormattedArray[rowCounter][columnCounter].setText(heldString);
                    userInputFormattedArray[rowCounter][columnCounter].setEditable(notEditable);
                }
            }
        }
    }

And this is where the answer comes from:

public static Integer[][] puzzleAnswerArray = new Integer[9][9];

public void getPuzzle() throws FileNotFoundException
    {
        Scanner puzzlesInFile = new Scanner(new FileReader("C:\\Users\\owner\\Desktop\\eclipse\\projects\\Sudoku\\Sudoku\\src\\puzzles.dat"));
        String searchParameter = "#puzzle" + intPuzzleSeed;
        int rowCounter = 0;
        int columnCounter = 0;

        //Prints the search parameter into the console, ensuring accuracy with the RNG.
        System.out.print(searchParameter);
        System.out.println();

        //
        puzzlesInFile.findWithinHorizon(searchParameter, 0);
        while (puzzlesInFile.hasNextInt())
        {
            for (rowCounter = 0; rowCounter <= 8; rowCounter += 1)
            {
                for (columnCounter = 0; columnCounter <= 8; columnCounter += 1)
                {
                    puzzleAnswerArray[rowCounter][columnCounter] = puzzlesInFile.nextInt();
                    System.out.print(puzzleAnswerArray[rowCounter][columnCounter].toString() + " ");
                }
                System.out.println();
            }
        }
        puzzlesInFile.close();
    }

I hope that this is enough info. Am I missing something obvious? Here is the console output from a completed puzzle, by the way:

The answers that are correct are (F is incorrect):
11 22 33 44 55 66 77 88 99
44 55 66 77 88 99 11 22 33
77 88 99 11 22 33 44 55 66
22 33 44 55 66 77 88 99 11
55 66 77 88 99 11 22 33 44
88 99 11 22 33 44 55 66 77
33 44 55 66 77 88 99 11 22
66 77 88 99 11 22 33 44 55
99 11 22 33 44 55 66 77 88

Here is the GUI:

—EDIT:I can’t post the GUI because I have less than 10 reputation. As soon as I get there, I will post a .png of the GUI.—

My guess would be that even though the “strings” are the same, it for some reason or another isn’t recognizing it as the same. Let me know if you need to see more code, but I think I covered everything.

  • 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-14T13:45:38+00:00Added an answer on June 14, 2026 at 1:45 pm

    You are using == for string equality check.

    if(gui.userInputFormattedArray[rowCounter][columnCounter].getText() == io.puzzleAnswerArray[rowCounter][columnCounter].toString()) {
    

    Use .equals() methods instead. And that applies not just for string but for any kind of objects. In case of objects == checks the identity of the objects.

    Try:

    if(gui.userInputFormattedArray[rowCounter][columnCounter].getText().equals(io.puzzleAnswerArray[rowCounter][columnCounter].toString())) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Salutations everyone, I have a somewhat strange problem with my repo. Initial I only
I'm currently writing a Rails app, and hit a somewhat strange quirk. I have
Admittedly, this is a strange problem for me to have, but here is what
My problem is somewhat strange. I have started developing a web page with Aptana
I have problem in updating mysql table. While the problem seems somewhat strange I'm
We have been debugging a strange case for some days now, and have somewhat
I have somewhat simple problem with my Flash projects. I've installed Flash CS5, created
I'm wondering if this is something somewhat simple, but I'm having a problem ONLY
I have a somewhat strange issue with visual studio. Almost every time I create
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef

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.